PHP script mysql içine csv veri almak için
Bu veritabanı içine csv veri almak sağlayacak basit bir betik. sadece, uygun alanlara düzenleyebilirsiniz çünkü csv dosyası ile birlikte yükleyerek web onu aramak ve dinlenme yapacak Bu kullanışlı geliyor.
O komada olup olmadığını, bu csv dosyasında sınırlayıcı belirlemenizi sağlar, bir sekme vb Ayrıca, hat ayırıcı seçti izin veriyor bir dosya (veri sql dökümü olarak da bilinir) çıktı kaydetmenize olanak verir.
Bu da genellikle birincil anahtar otomatik artış tamsayıdır her satır, başında boş bir alana dahil etmenize olanak sağlar.
Eğer phpMyAdmin yoksa esas ise, veya giriş güçlük istemiyorum ve bir kaç tıklama çözümü tercih Bu script yararlıdır, veya sadece bir komut istemi adam vardır.
Sadece tablo zaten veri dökümü denemeden önce oluşturulmuş olduğundan emin olun.
Eğer herhangi bir hata raporu var ise Lütfen yorumlarınızı gönderin.
Büyük bir kabuk! Tnx çok
Hi ...
Ben bir sorun bakacak, ben bu, onun bir hata söyleyerek gösteren kullandığınızda
"Önerilmeyen: Fonksiyon split () C önerilmemektedir: \ wamp \ www \ test1 \ simplecsvimport.php line 64
Dosya yazılabilir değil, izinleri kontrol edin. Bulunan bu csv dosyasında 41 kayıt toplam. "
Pls cevap, yanlış budur!
şimdiden teşekkürler!
Ben gerçekten bu kodu ile aklım karıştı!
ama ben denemek için alışkanlık!
BTW, kodu veya alan html bu kodu arama nasıl
Teşekkürler, çok iyi csv ithalatçı.
Ama küçük bir sorun bulunduğunda, sadece yapısı ile csv dosyası ile çalışır: "alan1", "alan2", "field3" vb ama ben böyle bir CSV dosyası hava: alan1, alan2, filed3; vb
Ben değiştirebilirsiniz tek şey ama fieldseparator $ olduğunu nasıl dosya (alan sınırlayıcı) "kullanımı olmadığı script 'söyle' mi?
Benim ideia ya $ bir combobox fieldseparator (oldu ve başka dolar ile bir fielddelimiter ("ya da hiçbir şey)
Şimdiden teşekkür ederim.
Onları virgülle alanları yeni bir kayıt olarak okumak alamadım böylece çift tırnak ile kapalı alanlara çalışması için bu komut nasıl olsun herhangi bir fikir?
Ben dolar tutar ve kullanıcıları bir virgül kullanmış olabilirsiniz bir yorum bölümü gibi virgül içeren veri var. Ben ve ithal tüm alanı ihtiyacı bu script yeni alanlar olarak ele alır.
Işareti Cloyd @
"Adres = DEĞERLERİ (adres)
'=' Beklenmeyen, sözdizimi hatası: Ben Ayrıştırma hatası olarak burada bir hata alıyorum
@ Joofoo
Ben senin kod yüklü var ama MySQL veritabanı üzerinde güncellenmiş bilgi almak ...
CSV içerir:
Başlık -> kullanıcı adı, şifre, mesaj, e-posta, resim, tarih
ROW2 -> Bill, dostum,,,,
Row3 -> Jane, kızım,,,,
Row4 -> David, çocuk,,,,
Ve burada kodu ...:
<? Php
/ / "Uzak" klasörünü-up iphonelogin.php dosyasından ayarlanır ...
/ * Db * bağlanmak /
/ / $ Link = mysql_connect ('ronbo.db.6405862.hostedresource.com', 'ronbo', 'Pepper0689') or die ('DB bağlanmak Can't');
/ / Mysql_select_db ('ronbo', $ link) or die ('DB seçilemiyor');
/ / https://www.ihappyapps.com/DataFolder/loader.php
/********************************/
/ * Code https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * Uygun değerleri yansıtmak için girişleri aşağıda Düzenle
/********************************/
$ Databasehost = "dbhost";
$ Databasename = "isim";
$ Databasetable = "tablo";
$ Databaseusername = "username";
$ Databasepassword = "password";
$ Fieldseparator = "";
$ Lineseparator = "\ n";
$ Csvfile = "spreadsheet.csv";
/********************************/
$ Addauto = 1;
/********************************/
$ = 0 kaydetmek;
$ Çıktıdosyası = "output.sql";
/********************************/
if (! file_exists ($ csvfile)) {
echo "Sunucu, ama istek var size veritabanına yüklemek istediğiniz CSV dosyası mevcut ... .. \ n";
exit;
}
$ = 1 * (1024 * 1024) chunksize;
$ Dosya = fopen ($ csvfile, "rb");
if (! $ dosya) {
"Açılış veri dosyası hata \ n". Yankı;
exit;
}
$ Size = filesize ($ csvfile);
if (! $ boyut) {
"Dosya boş \ n". Yankı;
exit;
}
$ Con = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ databasename) or die (mysql_error ());
$ Lines = 0;
$ Sorgu = "";
while (! feof ($ dosya)) {
$ Csvline = fgets ($ dosya, $ chunksize);
$ Hatları + +;
($ Hatları <2) devam ediyorsa;
$ Satır = ($ csvline, "\ t") Döşeme;
$ Satır = str_replace ("\ r ","",$ hat);
/************************************************* ************************************************** *********
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************************** ************************************************** ********/
$ Satır = str_replace ("'"," \ '", $ line);
/************************************************* ************************************************** ********/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$ Linemysql = implode ("','",$ linearray);
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
($ Tasarruf) $ sorgu .= $ sorgu eğer. "\ N";
@ Mysql_query ($ sorgu);
$ Satır echo "\ n".;
}
fclose ($ dosya);
$ Hatları -= 3;
@ Mysql_close ($ con);
<>
Ben gerçekten çalışmak için bu almak biraz yardım kullanabilirsiniz ...
Ron
@ Arda
Ben büyük dosyaları işleme zaman çok daha az bellek tüketir, böylece script değiştirilmiş (bu i bir 100mb CSV dosyası üzerinde kullanmak çalıştığımızda php bellek sınırı vurmak). aşağıdaki gibi değişiklikler şunlardır:
$chunksize = 1*(1024*1024);
$file = fopen($csvfile,"rb");
if(!$file) {
echo "Error opening data file.\n";
exit;
}
$ Size = filesize ($ csvfile);
if (! $ boyut) {
"Dosya boş \ n". Yankı;
exit;
}
$ Con = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ databasename) or die (mysql_error ());
$ Lines = 0;
$ Sorgu = "";
while (! feof ($ dosya)) {
$ Csvline = fgets ($ dosya, $ chunksize);
$ Hatları + +;
($ Hatları <2) devam ediyorsa;
$ Satır = ($ csvline, "\ t") Döşeme;
$ Satır = str_replace ("\ r ","",$ hat);
/************************************************* ************************************************** *********
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************************** ************************************************** ********/
$ Satır = str_replace ("'"," \ '", $ line);
/************************************************* ************************************************** ********/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$ Linemysql = implode ("','",$ linearray);
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
($ Tasarruf) $ sorgu .= $ sorgu eğer. "\ N";
@ Mysql_query ($ sorgu);
$ Satır echo "\ n".;
}
fclose ($ dosya);
$ Hatları -= 3;
@ Mysql_close ($ con);
Teşekkür ederim,
@ A Khaled
Nasıl UTF8 verebilirsiniz output.sql için excel
teşekkürler
Ama script çalıştı output.sql garip şeyler yazma olup,
!??????? Test_excel değerleri ('PK eklemek |? Q k5 q Q k5 q Q k5 q ....
bunlar gibi
nasıl bu sorunu çözebilirsiniz. için herhangi bir özel tabaka excel?
Merhaba guys, sadece tüm beni ihtiyacım gerçek program yazmak birini bulduk bildirmek istedim.
@ Warren
/********************************/
Bu dosya böylece o ihtiyacı birine bu programı yapmak için kaynak site ve diğer bilgi de yorum dayanarak 28 Aralık 2010 yılından itibaren üzerinde Warren (bir programcı) tarafından yapılan birçok teşebbüs değişiklikleri içerir. Bu çok eksik. Yardım en çok ve takdir çok ihtiyacı vardı.
Çizgiler web sitesi URL veritabanı adı ve şifre vs giriş kutuları oluşturmak için önce
/********************************/
Hoşgeldin Server Programı yükleyin
ve her bir dosya adı daha az uzatma yükleyerek, masa keywords_categories karşı bir cephe olarak benzersiz bir numara ile sonra sonra 1 numaralı atar: Bu program ile web sitenize yeni bir MySQL Veritabanı içinde iki boş masaları doldurmak için bilgisayarınızdan çalışır Bu dizin işlenmiş sonraki her dosya için tek bir dosyadan veri ve artar numarasının ilk Colum önünde boş sütununda tabloda kategori adının assigend sayı, hangi anahtar kelimelerin ve bunlara ait maçlar böylece Daha sonra masa anahtar kelime yükledi.
Bu sizin için belirli bir dizindeki tüm csv dosyaları için yapılır.
Sizin csv dosyasında ilk beş satır yok sayar.
Web sitesi URL:
Veritabanı Adı:
Veritabanı Kullanıcı Adı:
Veritabanı Şifre:
dosya yüklemek içeren Directory Yolu:
/********************************/
Soru
Nasıl aşağıda istenen maç programına giriş kutuları verileri yukarıda alabilirim?
/********************************/
<? Php
/********************************/
Line büyük dosyaları zaman aşımı önlemek ekledi.
/********************************/
(0) set_time_limit;
/********************************/
Daha sonra dosya adı uzantısı kaldırmak tablo keywords_categories için kategori adları olarak yüklemek için bunları kullanmak, işlenecek dosyaların dosya isimlerini alın.
/********************************/
/********************************/
adı uzantıları dosyayı kaldırır
org www perlmonks kopyalanan /? = 151.232 node_id
/********************************/
alt parse_out_extension {
die ("Hayır ayrıştırmak için dosya \ n".) if (@ _!);
benim ($ dosya) = @ _;
benim @ parçalar;
Harita {push (@ parçaları, $ _)} split (/ \ /, $ dosya.);
benim $ end = pop (@ adet);
$ File = ~ s / \ $ sonu / /.;
return ($ dosya) $ Eğer dosya;
/********************************/
* Orijinal kodu / https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * Uygun değerleri yansıtmak için girişleri aşağıda Düzenle
/********************************/
$ Databasehost = "localhost";
$ Databasename = "test";
$ Databasetable = "örnek";
$ Databaseusername = "test";
$ Databasepassword = "";
$ Fieldseparator = "";
$ Lineseparator = "\ n";
$ Csvfile = "filename.csv";
/********************************/
/ * Bu kayıtların başında bir ampty alanı eklemek ister misiniz?
anahtar kelimeleri bu yeni boş coum yer din Frot o atanan numarayı yakalar çok değiştirilmesi gereken dosya bazında bir dosya üzerinde her dosyada verilerin ilk sütununda anahtar durumunda Warren / * Not dosya adı daha az uzatma oluşur ve bu yeni boş ilk sütunda yerleştirir kategori adı.
Bir auto_increment tamsayı olan ilk alan bir tablo varsa, / * Bu yararlıdır. Warren tarafından unutmayın. Bu tabloda keywords_categories için upoaded dosya adları az exteniosn durumunda ihtiyaç budur.
/ * Ve csv dosya kayıtları önce boş alan gibi yok.
/ * Evet ve hayır 0 için 1 olarak ayarlayın. DİKKAT: Eğer emin değilseniz, 1 set yoktur.
Bu ekstra alan tabloda yoksa / * Bu yanlış alanlarda veri dökümü olabilir. Warren tarafından Not muhtemelen benim parçası olarak bu dosyaya davamı ama sadece bir tahmin gerekmez ama eğer varsa gerek görmek gerekiyor.
/********************************/
$ Addauto = 1;
/********************************/
/ * Eğer dosyada mysql sorguları kaydetmek ister misiniz? evet $ Eğer 1 set kaydedin.
/ Dosya * İzin 777 olarak ayarlanması gerekir. Ya ve ftp ile örnek bir dosya upload
/ *, Izinleri değiştirmek veya isteminde çalıştırın: dokunmatik output.sql & & 777 output.sql chmod
/********************************/
$ = 0 kaydetmek;
$ Çıktıdosyası = "output.sql";
/********************************/
if (! file_exists ($ csvfile)) {
echo "Dosya bulunamadı. Emin olun size doğru yolu belirtilen \ n ".;
exit;
}
$ Dosya = fopen ($ csvfile, "r");
if (! $ dosya) {
"Açılış veri dosyası hata \ n". Yankı;
exit;
}
$ Size = filesize ($ csvfile);
if (! $ boyut) {
"Dosya boş \ n". Yankı;
exit;
}
$ Csvcontent = fread ($ dosya, $ boyut);
fclose ($ dosya);
$ Con = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ databasename) or die (mysql_error ());
/********************************/
üstbilgi metin ve boş bir satır adveristing yılının ilk dört satır ekleyerek önlemek için. Hat sıfır kod eşit aşağıdaki kodu ile değiştirildi.
/********************************/
$ Lines = 1; (sayaç için değeri 1)
$ Sorgu = "";
$ Linearray = array ();
foreach ($ line olarak bölünmüş ($ lineseparator, $ csvcontent)) {
$ Hatları + +; (atar ilk satırı # 2 (başlık)
($ Hatlar> = 5) (# 5 "şey yüksek veya 5 eşit başlasın mı?) {If
$ Sorgu = "";
$ Linearray = array ();
foreach ($ line olarak bölünmüş ($ lineseparator, $ csvcontent)) {
$ Hatları + +;
$ Satır = ($ line, "\ t") Döşeme;
$ Satır = str_replace ("\ r ","",$ hat);
/************************************
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************/
$ Satır = str_replace ("'"," \ '", $ line);
/*************************************/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$ Linemysql = implode ("','",$ linearray);
($ Addauto) ise
linemysql');"; (",'$ $ databasetable değerlere $ sorgu = "insert
başka
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
$ Sorgu .= $ sorgu. "\ N";
/************************************
Bu kod biraz aşağıda şimdi hata mesajları göstermek için eklendi.
************************************/
$ Result = mysql_query ($ sorgu);
/ / Sonucu kontrol edin
/ / Bu MySQL gönderilen gerçek sorgu ve hata gösterir. hata ayıklama için kullanışlıdır.
if (! $ result) {
$ Mesaj = 'Geçersiz sorgu:'. mysql_error (). "\ N";
$ Message .= 'Tüm sorgu:'. $ Sorgu;
($ Mesaj) die
}
@ Mysql_close ($ con);
if ($ tasarruf) {
if (! is_writable ($ çıktıdosyası)) {
echo ". Dosyası, kontrol izinleri \ n yazılabilir değil";
}
else {
$ Dosya2 = fopen ($ çıktıdosyası, "w");
if (! $ dosya2) {
". Çıktı dosyası \ n yazma hatası" yankı;
}
else {
($ Dosya2, $ sorgu) fwrite;
($ Dosya2) fclose;
}
}
}
"Bu csv dosyası Bulunan $ hatları kayıtlar toplam \ n". Yankı;
?>
isteğim, ben aslında denir sözü MqSQL veritabanındaki iki tablo Just hafif bir düzeltme:
keywords_categories
anahtar kelimeler
@ Warren
Ayrıca, sırf meraktan da bir txt dosyası, (bu kelime sadece bir liste var ki) aynı şekilde süreç olabilir?
(Ben, bu yeni ve ben çok soruyor olabilirsiniz bilmek, uygun olup olmadığını kimse, benim için bu küçük proje sürebilir eğer öyleyse, belki benim değişiklik yapma zaman için bir miktar ödeme tartışabilir benim ihtiyaçlarını karşılayacak? bana bildirin.)
Benim e-mail: wr.spence @ hotmail.com
Ben bir programcı değilim. Ben senin script görmek ve ya da, ben ne gerek yakın olabilir belki ne gerek temelini oluşturan olabilir, emin değilim.
Ben farklı bir MySQL DB ve aynı csv dosyaların bir listesi için, tekrar tekrar ama farklı bir alt dizinden benim sabit disk her zaman yükleme fonksiyonu gerçekleştirmek için her zaman (bir differret web sitesi her zaman) gerek. Birçok durumda db içinde herhangi bir veri yok, ancak script hala) mevcut verileri etkilemeden, veri var mı bir db ile işe yarayabilir eğer (ancak zorunlu değil) ideal olacaktır.
Ben (bu sitenin URL'sini ve db kullanıcı adı ve şifre vs için bana sormalısınız) sunucu üzerinde db için giriş yapmanız gerekiyor.
Beni arayabilir ve benim sabit diskinizde bir dizin adını almak, ya da girmenize olanak sağlar şeye ihtiyacım var.
O zaman, bu dizindeki bir birbiri ardına her csv dosyası süreci aşağıdaki gibidir:
Her dosyanın üzerine ben ilk dosya adı (az uzantılı) almak ve masa kategorisinde db yüklemek gerekir. Bu tablo o zaman bu ismi atanmış bir numaralı anahtar içerir.
Daha sonra, masa kelimeleri bu dosyayı sadece kelime Colum (veri 1 Colum) upload ve ilk dosyadan kategori adı için uygun nubmer eklemek komut dosyasına gerek.
O CSV dosya genellikle, başlığında metin ve boş bir satır üç satır içerdiğini belirtmek gerekir ki I ve ihmal istediğiniz tarih değil dört. Ben de, bu göz ardı etmek istediğiniz dosyanın te eend de boş satır gibi veya csv dosyasında olmayabilir başka sütunlar gözardı sıklıkla vardır. Bazı durumlarda csv dosyası herhangi bir başlık veya başka sütunlar olmayabilir.
Daha sonraki dosya, bu dizindeki dosyaların bitene kadar.
Sonra onu bana söylemek istiyorum "Süreci tamamlamak." Ve hataları bana eğer.
çocuklar bu konuda bana yardımcı Sizden miyim?
paylaşım için teşekkürler script mysql excel, bu benim için çok yararlıdır.
ya kod çalışıyor ama nw virgül ters alıyorum içine benim veri @ Suman
@ Pruthvi
Merhaba,
verilen kod feryat kullanın ... ...
Rendeleyin Kodu Gerçekten tüm PHP geliştiricisi yararlı olur.
) Sorgu ($ siz mysql_query @ yerini açıklamak kodunuzu istediğiniz için; verdi tablolar u ama mesaj $ bir hata olduğunu gösteriyor undefined @ Andrew Balık
bana sorun aynı @ Andrew Balık
En son gelişme kodu csv dosyasında satır ama tablo içinde görünmüyor onun hiç bir algılayabilir
kodu csv dosyasını bulamadım bir bildirimde dönüyor ...
wat sorun olabilir ....
Tamam, sorun bulundu. Ben tablo adı mispelt vardı. Ama sadece ben sql başarısız olursa bir hata döndürecektir aşağıdaki kodu eklemişti sorunu buldum. Bir sorun olduğunda eğer şu anda script söylemez.
Bu yüzden hat değiştirmek
@ Mysql_query ($ sorgu);
Aşağıdaki tüm -
$ Result = mysql_query ($ sorgu);
/ / Sonucu kontrol edin
/ / Bu MySQL gönderilen gerçek sorgu ve hata gösterir. hata ayıklama için kullanışlıdır.
if (! $ result) {
$ Mesaj = 'Geçersiz sorgu:'. mysql_error (). "\ N";
$ Message .= 'Tüm sorgu:'. $ Sorgu;
($ Mesaj) die
Umarım ki birileri yardımcı olur. Bana yaptı.
AJ
@ Andrew Balık
Ben doğru PHP Admin kullanarak ithalat bildiğiniz bir csv kullanarak bu komut dosyası çalıştırdığınızda, komut dosyası çalıştıran, mesajla "Bulunan bu csv dosyasında 193 kayıt olmak üzere toplam." Satır doğru sayıda raporlar ancak verilerin hiçbiri görünür tablo. O yüzden veri tabloya koymak denetler ve değil görebilirsiniz csv değişiklik yaptık. Herhangi bir fikir?
AJ
Benim CSV dosyası da bu yüzden veri tırnak ile kayıt ekleme oldu bu sorun vardı, (Ben verileri bozmak yok öyle Excel'e almak gerekiyorsa esas sorunlardan kaçınmak için) her sahada çift tırnak vardır. Bu satır ekleyerek tüm çift tırnak elimden:
$ Satır = str_replace ("\ "","",$ hat);
Bu satırdan sonra:
$ Satır = str_replace ("\ r ","",$ hat);
ve yeni hat hiçbir şey ile çift tırnak yerine geçer. Onu çıkarmadan müzik dışında \ "\ r (return yerine çift tırnak) yerine daha önce çizgi olarak aynıdır.
@ Neady
Büyük küçük bir program.
bir hücre gibi verileri değiştirmek için bir yol var mı. csv 'şehir' ve $ _SESSION veya $ _POST değeri gibi bir önceki sayfadan bir değer olarak değiştirin?
Bu büyük ... çok uygulamak kolaydır. Şimdi bana nasıl upload bu veya benzeri komut dizisini kullanmak için. Xls ile birlikte dosya bulmalısınız. Csv dosyası
@ Mike
Eklediğiniz deneyebilir miyim:
(0) set_time_limit;
başında sağda? (Php açılış etiketi hemen sonra)
@ Exclusive Rehberler
bir şekilde o zaman aşımı yok var mı? o zaman ben bir mil ya da daha fazla gibi büyük bir şey için gitmek, ama 100k kayıtları ile büyük işler sonra boş bir ekran ve reklamları kayıtları gider yaklaşık 20 saniye için çalışır.? Teşekkürler.
aynı sorunu yaşıyorsunuz, herkes lütfen yardımcı olabilir?
HI arkadaşlar,
Ben kodu ... Öyleyse lütfen bana yardım sizden acil yardım gerekli ...
HTML dosyası hazırladı. Ama ihtiyacım var php çözüm ... Lütfen bana yardım ... ... ..
SMS gönder
Alıcı Cep Numarası:
+91
Telefon rehberi
Dosya Yükle Excel:
<!-->
<Input type = "file" name = "dosya" class = "file_input_hidden" onchange = "javascript: document.getElementBy
Gönderenin kimliği:
:
YOGA
GRAFS
Mobitel
var frmvalidator = new Validator ('freesms2');
frmvalidator.addValidation ("frno", "req", "cep telefonu numarasını girin");
("Frno", "num", "Mobil numara alan sayılar içermeli") frmvalidator.addValidation;
frmvalidator.addValidation ("frno", "minlength = 10000", "Mobil numara 10000 hane olmalı");
frmvalidator.addValidation ("message3", "req", "SMS metni girin");
iyi ile ilgili
Ravi Kumar
<? Php
$ = '0 'Newbal;
"Conn.php" arasında;
if (isset ($ _POST ['to']))
{
$ Dosya = $ _POST ['dosya'];
$ Handle = fopen ("$ dosya", "r");
(($ Veri = fgetcsv ($ kolu, 1000, ","))! == YANLIŞ) ise
{
$ Sql5 öğeden = mysql_query ("select * nerede item = $ veri [0 ]'");
$ Num = mysql_num_rows ($ sql5);
($ Num == 0)
{
$ Ithalat = "[0 ]','$ veri INSERT öğe (öğe, gweight, dweight) değerlere ('$ veri 1 ]','$ verileri 2 ]')"; [[
mysql_query ($ ithalat) or die (mysql_error ());
}
else {
"$ Veri [0] exit" echo;
}
}
fclose ($ handle);
print "yapılan ithalat";
}
başka
{
?>
Almak Tipi dosya adı:
Tarih
setIcon ("images / iconCalendar.gif");
$ MyCalendar-> setDate (date ('d'), tarih ('m'), tarih ('Y'));
$ MyCalendar-> setPath ("./");
$ MyCalendar-> setYearInterval (2010, 2020);
$ MyCalendar-> dateAllow ('2008-05-13 ', '2020-12-31');
$ MyCalendar-> setDateFormat ('Y / m / d');
$ MyCalendar-> writeScript ();
?>
bunu önceden bana, teşekkür yardım sunucusuyla çalıştıklarında i localhost csv dosyası yüklediğinizde ama göstermek dosya eksik hata gayet iyi çalışıyor
Ben bu sql içine alışveriş sepeti's csv için iyi olduğunu düşünüyorum.
kaundo le doy descarga bana aparecen muchos fermuarlar todos los archivos los ubico en una sola carpeta? ¿
@ Zeshan
split yerine patlayabilir kullanımı
Önerilmeyen: Fonksiyon split () E önerilmemektedir: \ wamp \ www \ floodpk2 \ admin \ simplecsvimport.php hat 63
Dosya yazılabilir değil, izinleri kontrol edin. Bulunan bu csv dosyasında 1498 kayıtları toplam.
acilen bana yardım plz
8pills.com tek bir yerden sağlık çözümdür. 8pills.com sınıf Genel ve Markalı ilaçlar iyi sağlamak.
i aşağıda haber bakan am-
Haber: 1 C: ofset Undefined \ wamp \ www \ Yeni Klasör (2) \ exl8.php line 20
Haber: 2 C: ofset Undefined \ wamp \ www \ Yeni Klasör (2) \ exl8.php line 20
Haber: 2 C: ofset Undefined \ wamp \ www \ Yeni Klasör (2) \ exl8.php line 20
Bu çok iyi çalışıyor. Teşekkürler!
Burada, kod btw olduğunu
$ Databasehost = "localhost";
$ Databasename = "veritabanı";
$ Databasetable = "tablo";
$ Databaseusername = "admin";
$ Databasepassword = "admin";
$ Fieldseparator = "";
$ Lineseparator = "\ n";
$ Csvfile = "https://linktosite/";
$ Addauto = 0;
$ = 0 kaydetmek;
$ Çıktıdosyası = "output.sql"; / / kaydederseniz logo (1)
$ Dosya = fopen ($ csvfile, "rb");
$ Csvcontent = stream_get_contents ($ dosya);
fclose ($ dosya);
$ Con = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ databasename) or die (mysql_error ());
$ Lines = 0;
$ Sorgu = "";
$ Linearray = array ();
foreach ($ line olarak bölünmüş ($ lineseparator, $ csvcontent)) {
$ Hatları + +;
$ Satır = ($ line, "\ t") Döşeme;
$ Satır = str_replace ("\ r ","",$ hat);
/************************************
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************/
$ Satır = str_replace ("'"," \ '", $ line);
/*************************************/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$ Linemysql = implode ("','",$ linearray);
($ Addauto) ise
linemysql');"; (",'$ $ databasetable değerlere $ sorgu = "insert
başka
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
$ Sorgu .= $ sorgu. "\ N";
@ Mysql_query ($ sorgu);
}
@ Mysql_close ($ con);
if ($ tasarruf) {
if (! is_writable ($ çıktıdosyası)) {
echo ". Dosyası, kontrol izinleri \ n yazılabilir değil";
}
else {
$ Dosya2 = fopen ($ çıktıdosyası, "w");
if (! $ dosya2) {
". Çıktı dosyası \ n yazma hatası" yankı;
}
else {
($ Dosya2, $ sorgu) fwrite;
($ Dosya2) fclose;
}
}
}
Bu csv dosyasında "Bulunan $ hatları kayıtlar toplam yankı. . \ N "DB eklenir;
Merhaba,
Ben mysql datafeed bir csv almak için bu komut dosyası kullanabilirsiniz.
Tek sorun benim sahip, tırnak "" Ayrıca benim tabloları takılı olmasıdır
Sınırlayıcı: (komma)
Muhafaza: "(aanhalingsteken)
Yeni hat: \ r \ n
Güzel çalışma!
Ben sadece bir soru var.
mümkün komut komando patlamaya daha fazla karakter kullanmak mümkün müdür?
Ben allso bir bir ayrılık olduğunu gerekiyor. ve;
çok bazı vücut herhangi bir fikir varsa teşekkür ederiz!
Sitemde de bunu uygulamak için bu kodu ... ... ... Seni çok kolay ... ..
Çok teşekkür ederim ..
Ben php için biraz daha kod istiyorum ... ...
pdf sayfa çevirmek için ...
Merhaba,
Bu hata alınıyor. nasıl bu sorunu çözmek için?
Hata:
Dosya yazılabilir değil, izinleri kontrol edin. Bulunan bu csv dosyası 13 kayıt toplam.
Teşekkürler
Haan
Hmm .. ben bu "Dosya gibi hatalar, kontrol izinlerini yazılabilir değil var. Bulunan bu csv dosyası 2 kayıt toplam. "Neyin yanlış giden herhangi bir fikir?
Hmm .. ben bu "Dosya gibi hatalar, kontrol izinlerini yazılabilir değil var. Bulunan bu csv dosyası 2 kayıt toplam. "Neyin yanlış giden herhangi bir fikir?
İlk satır / satır csv dosyası bir başlık olduğunu atlamak için şunu yapın:
... ..
($ Hatlar> 1) {if
($ Addauto) ise
linemysql');"; (",'$ $ databasetable değerlere $ sorgu = "insert
başka
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
$ Sorgu .= $ sorgu. "\ N";
@ Mysql_query ($ sorgu);
}
Ben farklı bir etki altında iyi çalışan bu komut vardı. i taşındı Sonra zaman, cron indirme csv dosyası, saklar, sonra da kaldırır ama doesnt mysql yükleyin. Ne zaman i import.php dosya bakıyorum ve ben dosyayı doğru yol olduğundan emin olun bulamıyorum söyleyerek hata yürütmek için deneyin. Yardımcı olur.
sadece, örneğin karşı oynamak, ilk satır ekleyerek önlemek istiyorsanız:
$ Lines = 1; (sayaç için değeri 1)
$ Sorgu = "";
$ Linearray = array ();
foreach ($ line olarak bölünmüş ($ lineseparator, $ csvcontent)) {
$ Hatları + +; (atar ilk satırı # 2 (başlık)
($ Hatlar> = 3) {(# 3 "bir şey daha yüksek veya 3 eşit" başla) if
Harika bir script ama yineleyen sorunlar yaşıyorum.
Ben komut çalıştırıldıktan sonra, bu "Bulunan bu csv dosyasında 1 kayıt toplam." Diyor.
Ben tabloda geriye baktım ve boş gösteriyor.
Eminim ve sütunların sağ sayısı vardı vardı yapmak için kontrol edilmelidir.
Lütfen yardım edin!
Teşekkürler,
Coulton
Ben müşteri sabitdisk erişimini sınırlı olursam nasıl kontrol yükleme dosyasına biz varsayılan bir değer server.for örnek csv dosya yüklemek için gidiyorum
Bu benim için çok faydalı oldu ... ama büyük dosyaları okumak için bir değişiklik yapmak gerekiyordu. Ama ilk başta şaşırmıştı sonra bellek (değil mi?) Içine betiğin yüklediği tüm dosyayı gerçekleştirdi. Yani burada bir defada bir satır okur kodu, özelleştirilmiş bir versiyonudur. benziyor dosyaları okur
dosya başlar:
2,3, -1
1, -2,4
sonunda dosya (daha birçok değerleri ile). i bir tablo girişi ve hat numarası ile bir id yanı sıra tablonun boyutu (daha sonra değişmeyecek olan) temsil eden ilk id olmak her satırı istedi.
<? Php
/********************************/
/ * Code https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * Uygun değerleri yansıtmak için girişleri aşağıda Düzenle
/********************************/
$ Databasehost = "localhost";
$ Databasename = "tomoku";
$ Databaseusername = "root";
$ Databasepassword = "root";
$ Fieldseparator = "\ n";
$ Lineseparator = "\ n";
/ / Bu kod veritabanına tatami dosyalarını okuma
$ Con = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ databasename) or die (mysql_error ());
dosyaların bir demet üzerinde / / Bu döngüler
{(;; $ R <14 $ r + + $ r = 2)
($ C = $ r; $ c
Aşağıdaki benim için hile yaptı:
LOAD DATA LOW_PRIORITY YEREL INFILE
'C: \ \ Documents and Settings \ \ Administrator \ \ Desktop \ \ SigmaS1.csv'
INTO TABLE `mydb`. `Mytable`
ALANLARI BY kaçtı '\ \'
',' BY DURDURULAN
OPSİYONEL '"' BY MAHFAZALI
BY DURDURULAN HATLARI '\ r \ n'
(`Kullanım`, `Sno`, `AMT`, `ActiveRec`, `pwd);
Script csv dosyasından bir satır okuyor. csv dosyaları örn. Bu 26 kayıtlar vardır gösteren 25 kayıt var. eğer yanlış gidiyorum nerede bana bahseder misiniz?
Ben ilk basamak olup olmadığını kontrol etmek ve döngü devam eklediğiniz ilk çizgi halinde.
teşekkürler
Gary gibi, ama varolan bir rekor üzerine yazmak mümkün istiyorum bu güncelleme, db tüm verileri silme değil. Buralarda Sp:
($ Addauto) ise
linemysql');"; (",'$ $ databasetable değerlere $ sorgu = "insert
başka
$ Sorgu = "insert $ databasetable değerleri ('içine $ linemysql');";
Nasıl kayıt varsa ve ardından Ekle ziyade Update kontrol edin istiyorsunuz?
Nasıl csv dosyası ve eklemek db içine veri geri kalanında bir başlıktır / satır ilk satırı atlamak mı?
@ Gary
Eğer ("$ databasetable kesmek") bir @ mysql_query kullanabilirsiniz; @ mysql_select_db deyimi hemen sonra.
Ama bu eylem verileri silecek gibi ve geri dönüşümü olmayan dikkatli olun.
@ Kish
geçerli kod / dosya yüklemek için tarama izin vermez.
Sadece ve PHP script olarak aynı dizinde CSV dosyası koyabilirsiniz sadece dosya adı (yol hariç) eşit olmak $ csvfile değişken seti
Merhabalar,
Nasıl bu csv tarihi "gün, ay tarih, 2010" ve devlet "prov, devlet" benim veri tabanı bir sütuna tırnak içerir mi? Ben birçok örnek ama bunun işe göremez. herhangi bir yardım iyi olurdu.
ak, 10037591,1, "Salı, 9 Mart 2010 15:55:16", 59,7151, -151.4434,2.7,75.90,32, "Kenai Yarımadası, Alaska"
thx
Teşekkürler, bu kod gerçekten yardımcı oldu!
Nasıl kullanıcı göz içinde ve seçer csv dosyası tablo ithal edilecek bir form gösterilmesine izin değiştirmek istiyorsunuz?
Ve aynı zamanda nasıl bu kadar ne olursa olsun şu anda tabloda depolanan yeni bir dosya geçersiz olacağını gönderilen her zaman olduğu yapabilirdiniz?
Çok teşekkürler
Bu benim için çok faydalı kodu ..
teşekkürler.
Nasıl yerine tam yol adını yazarak dosya arayabilir alabilirsiniz ..
bu konuda yardımcı olun.
teşekkürler
i bir dosya kontrolü çalışabilir nasıl alamadım. demek ilk göz ve bir dosya seçin ve i lüzum modifiye nereye teslim
Merhaba,
bazı değişiklikler yapılmıştır. . "|" (Pipe) karakteri benim txt dosyası ile ayrılmış 3 sütun vardır. Komut dosyası, dosya verilerini görüntüler satırları sayar, ama veritabanına veri girmiyor. Herhangi bir yorum?
$ Csvcontent = fread ($ dosya, $ boyut);
fclose ($ dosya);
$ Con = @ ($ dbhost, $ dbusername, $ dbuserpassword) mysql_connect veya (mysql_error ()) die;
@ Mysql_select_db ($ veri kaynağı) or die (mysql_error ());
$ Lineseparator = "\ n";
$ Fieldseparator = "|";
$ Lines = 0;
$ Sorgu = "";
$ Linearray = array ();
$ Count = 0;
foreach ($ line olarak bölünmüş ($ lineseparator, $ csvcontent)) {
$ Count = $ count + 1;
$ Hatları + +;
$ Satır = ($ line, "\ t") Döşeme;
$ Satır = str_replace ("\ r ","",$ hat);
/************************************
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************/
$ Satır = str_replace ("'"," \ '", $ line);
/*************************************/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$ Linemysql = implode (""",$ linearray);
($ Addauto) ise
GÖSTERGELER değerleri ($ count ',' $ linemysql');"; içine $ sorgu = "insert
başka
GÖSTERGELER değerleri ('içine $ sorgu = "insert $ linemysql');";
$ Sorgu .= $ sorgu. "\ N";
@ Mysql_query ($ sorgu) or die (mysql_error ());
"$ Linemysql \ n" echo;
}
Mükemmel script! Ben üzerinde çalışıyordu ve bu hile yaptı bir proje için biraz atlama başlangıç gerekiyordu.
Ben bir form ile çalışmak için komut değiştirilmiş ve yeni çizgi karakter (ya \ r \ n veya her ikisi) hala kayıt ediliyordu çünkü aramak için, son alanına kadar buggered başlamıştı fark ettiniz fark bir şey ancak garip yaptı MySQL veritabanı.
Bu amaçla, için, değiştirmek gerekir:
$ Satır = str_replace ("\ r ","",$ hat);
ile:
$ Satır = str_replace ('\ r',",$ hat);
Bu yeni hat olarak, bir sorun olmaktan geri tutacak, ben yeni kayıt eklemek için izin veren bir şeyler ekledim, ama güncelleştirmeler yinelenen girişleri ile sonunda yok ki, kayıtlar mevcut. Aşağıdaki kodu üst kısmında, ben gerçek yeni çizgi karakter için aynı düzeltmeyi yaptı nerede göreceksiniz.
$ Linemysql = implode ("','",$ linearray);
$ Newlinemysql = str_replace ('\ n',",$ linemysql);
($ Addauto) {if
($ Databasetable) anahtarı {
durumunda ('adres'):
$ Duplicatevals = "adres = DEĞERLERİ (adres),
şehir = VALUES (şehir), devlet = DEĞERLER (devlet),
zip = DEĞERLERİ (zip) ";
break;
durumunda ('sahibi'):
$ Duplicatevals = "ownername = VALUES (ownername)
housetype = VALUES (housetype)
addresskey = DEĞERLERİ (addresskey) ";
break;
}
$ Databasetable değerlere $ sorgu = "insert (",'$ newlinemysql ')
KEY UPDATE yinelenen ON
$ Duplicatevals ";
} Else {
$ Içine $ sorgu = "insert databasetable değerler ('$ linemysql')
KEY UPDATE yinelenen ON
$ Duplicatevals ";
}
Ayrıca, benim şeklinde ben simplecsvimport üstündeki sonucu bölünmüş, sonra ben açılan tek bir giriş (virgülle ayrılmış) olarak ya da "addauto" [boolean] olmak tablo istemiyordu olmadığını ve tablo adını koydu script.
Finally, you have to remember to set indexes in the database for the, “ON DUPLICATE…” to work, auto increments will not work in this case, so you have to set a secondary index on the auto increment tables, the tables that don't auto increment and have unique fields work with the single index if that is the route you would like to go.
I hope this helps someone!
Şerefe!
I need to download data automatically from a remote server. Its a CSV file, and i need to unzip it, and store the data in a mysql database that i created. There are multiple databases. The first section below is one of the databases that someone helped me with and it works wonderfully. I set up a cron job and it downloads it automatically as scheduled. However i have more databases and cant get the others to work.
THIS SECTION BELOW WORKS FINE!!!!
—————————————————————————–
#!/bin/bash
deleteparam='–delete-after';
#deleteparam=”
#directory='–directory-prefix=/$HOME/myfolder/myfolder/'
directory=”
#userpwd='–http-user=blah –http-password=blah'
toUpper() {
echo $1 | tr “[:lower:]” “[:upper:]”
}
#if [ -z "$1" ]; then
# echo usage: $0 table
#exit
#fi
ZIP=name of data file in remote server
ZIP=`toUpper $ZIP`
#the file within the zip has one less _
DATA=name of table in my mysql database
DATA=`toUpper $DATA`
#rm $TABLE.csv.zip
#rm $DATA.csv
cd /$HOME/myfolder/myfolder/
#######get the residential
wget ' https://3pv.mlslirealtor.com/Data3pv/DownloadBRSaction.asp?user_code=XXXXXX&password=XXXXXXX&data_type=datazip ' -O $ZIP.csv.zip
sleep 10
#######unzip it
pwd
ls -la
unzip -o $ZIP.csv.zip
sleep 10
#######load it
wget –verbose $deleteparam $directory $userpwd https://mywebsite/myfolder/import.php?table=$DATA
sleep 300
######delete the files
rm $ZIP.csv.zip
rm $DATA.csv
sleep 10
_———————————————————————————
ALL OF THIS ABOVE WORKS WONDERFUL
THIS IS WHAT I NEED HELP WITH
—————————————————————————-
1. I need a script to add to the above file that will download the photos. If you see below i need a script that automatically gets the CURRENT date and time that the script is ran. There server holds pic from the last 7 days and is constantly updated. Once this script is ran it will download the data into the table that i created.
2. Then, I need a script that queries the mysql database looking for entries that have photos and then retrieve the actual photos directly from their remote servers. This csv file DOES NOT download photos, just data that i can use to run a script to retrieve the photos at a given spot. See below.
Below are the instructions I received.
INSTRUCTIONS
Photo data is retrieved by HTTP. The photos data is updated once daily and is available for download as a CSV file. You can then write a script using the data from the CSV file to point back to the images on our image server. YOU MUST SUPPLY A VALUE FOR THE QUERY STRING last_updt > 'YYYYMMDD HH:MM:SS' for the URL to return data. The field last_updt is the date value for the last time that a photo was changed on the listing.
You will need to replace the user_code and password place holders (XXXX) with the login credentials provided to you.
Step 1: To retrieve the primary listing photo data CSV file go to the URL below.
https://remotewebserver/Data3pv/DownloadBRSaction.asp?user_code=XXX&password=XXXX&query_str=last_updt%20>%20'YYYYMMDD%20HH:MM:SS'&data_type=PHOTOS
Step 2: The photos table data should download in a CSV format.
Step 3: Using the Y flags and the ML Number in the data you can link back to our image locations.
Our primary image directory path is as follows:
https://remoteserver/folder/folder/folder/Last3DigistsofML#/listing#.jpg
For example- The primary photo for listing number 1899430 is located at
https://remoteserver/folder/folder/1/430/1899430.jpg
Our additional image directory path structure is as follows:
https://remoteserver/mlsphotos/full/PhotoPosition/Last3DigistsofML#/listing#_photoPosition.jpg
For example- The second photo for listing number 1899430 is located at
https://remoteserver/folder/folder/2/430/1899430_2.jpg
Hi, it tells me the record count but not putting data into database
Hope you can help
Nathan
the command is: truncate tablename.
you can insert the following on line 58:
@mysql_query(“truncate $databasetable”);
but this is non reversible! so be careful
how can i empty my already filled table before inserting the new file?
or can i update an already existing input?
TRUNCATE, UPDATE? how do i get this in the query?
@Andy Brotherton : This means that the query is attempting to insert a record with a number of columns that do not match that of the database table.
1) Are you sure that the CSV file has the exact same number of columns as the table in the database?
2) Is the field separator in this CSV file really a comma? or is it a tab for instance or other? If it's not a comma, change the value of $fieldseparator on line 12
3) The table need to be already created in the database before attempting to load data into it. Are you sure you have it?
Merhaba,
I would really like to use this script but I'm not sure what I am doing wrong. I get the same problem mentioned above with data not loading into the db. It finds the correct number of rows but nothing shows in the db.
I changed line 88 @mysql_query($query) or die(mysql_error());
and get this message “Column count doesn't match value count at row 1″
@Claus
Hello Claus.
Does the CSV really contain a single record?
Since the script reached the stage where it outputs the number of records, I assume it didn't fail when it connected to the database (lines 56-57) so that is not the problem.
It is possible that the query to insert data is failing.
Try replacing line 88 with:
mysql_query($query) or die(mysql_error());
and check what error you get.
@Okoth
Hello Okoth.
Most likely, you can get rid of lines 33-54 and replace them with this single line:
$csvcontent = @file_get_contents("https://. . .");
replace the dots with the appropriate url (direct url to the CSV file)
@Adrian
Hello Adrian.
Drupal, as you noted, has complex table structures. Depending on what sort of data you are importing, it's very likely that this data needs to be split into multiple tables, usually with a common foreign key such as the node id.
Unfortunately, the script above wouldn't help do that.
Thanks for the script. Very understandable.
How can I modify this script so that it fetches and store a csv file from the Internet into MySQL?
Hi All
I am using drupal to build a new website, the challenge I am having right now is that I need to import data from a CSV file into a mysql database which has shared tables, therefore some of the fields into which I need to import csv data are in different sections of the same database will this script work for me? If not can this csv file be imported using another method?
Please advise, thank you for any assistance.
Saygılar
Adrian
Hi everyone!
Seem to have the script working…exept that it does not write data to the mysql…
Like with Chris: The script completes, and even outputs the record count, but doesn't touch the database at all… but tells me: Found a total of 1 records in this csv file.
What do I do wrong (im a noob at php and mysql)
Teşekkürler
Claus
Hi Stanley, the problem is with the single quotes. The blog software here rewrites them. Simply replace ' and ' with '
PS: the command above is to directly load a csv file into the database from the mysql prompt. This is nice but not related to the script above
it says to load this into the data base
load data local infile 'PATH' into table TABLE fields terminated by ',' lines terminated by '\n';
i change the path and the table its going into but it gives me an error that its the wrong syntax code 1064
can anyone give me some advise on what to do
teşekkürler
stan
With regards to the quotes issue, you can just use this:
$linearray = preg_split(“/,(?=(?:[^\"]*\”[^\"]*\”)*(?![^\"]*\”))/”, $line);
Şerefe,
Gaz.
Dear Chris,
please replace:
@ Mysql_query ($ sorgu);
with:
@mysql_query($query) or die(mysql_error());
and let me know what error it gives you
Hey Everyone,
Love this script, and it was working fine, now suddenly the script wont insert the records. The script completes, and even outputs the record count, but doesn't touch the database at all…
Herhangi bir fikir?
Teşekkürler
C
Merhaba Mark,
first, it's referring to the file you selected in the $outputfile variable.
second, this file needs to be writable. I assume you're using Linux, not windows, as this is generally not an issue with windows.
On linux, simply SSH to the machine, change to the directory where the output file is, and type: chmod 777 filename
where 'filename' is the actual file name.
If you don't have SSH, many FTP clients support permission change. For this purpose, FTP to the folder containing the output file, then select this file, and locate from this ftp software the option to change permission. Set it to 777, or 'read, write, execute' for everyone.
Merhabalar,
Thanks for the script. I'ma noob at PHP and MySQL so I really appreciate something like this. I got as far as generating the “File is not writable, check permissions” error message in my browser. Can someone please explain the comment about setting the permission to 777? I'm using an Excel-generated .csv file? Şimdiden teşekkür ederim.
I can only get the first line of my CSV file to be imported into the database.
Here's a copy of the log file:
insert into production values(”,'2008-10-21′,'50′,'50′,'50′,'this is the first notes line','this is notes line 2′,'this is notes line 3′,'0000-00-00′,'0000-00-00′,'0000-00-00′,'456 Morningside Ave','ste. 512′,'Brooklyn','NY','10023′,'Joe','Customer 1′);
insert into production values(”,'2008-10-09′,'50′,'50′,'50′,'this is the first notes line',”,”,'2008-10-09′,'2008-10-14′,'0000-00-00′,'456 Morningside Ave','ste. 512′,'Brooklyn','NY','10023′,'Joe','Customer 1′);
insert into production values(”,'2008-10-14′,'25′,'25′,'25′,'NOTES 1′,”,”,'2008-10-14′,'2008-10-17′,'NULL','555 somewhere','suite 123′,'new york','new y','10001′,'Joe','Name 1′);
insert into production values(”,'2008-10-16′,'45′,'45′,'45′,”,”,”,'2008-10-16′,'2008-10-24′,'NULL',”,”,”,”,”,'Tom',”);
insert into production values(”,'2008-10-01′,'34′,'34′,'34′,”,”,”,'2008-10-02′,'2008-10-04′,'2008-10-04′,”,”,”,”,”,'Steve',”);
insert into production values(”,'2008-10-17′,'50′,'50′,'50′,'this is the first notes line',”,”,'2008-10-03′,'0000-00-00′,'0000-00-00′,'456 Morningside Ave','ste. 512′,'Brooklyn','NY','10023′,'Joe','Customer 1′);
insert into production values(”,'2008-10-18′,'25′,'25′,'25′,'NOTES 1′,”,”,'2008-10-04′,'0000-00-00′,'0000-00-00′,'555 somewhere','suite 123′,'new york','new y','10001′,'Joe','Name 1′);
insert into production values(”,'2008-10-19′,'45′,'45′,'45′,”,”,”,'2008-10-05′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,'Tom',”);
insert into production values(”,'2008-10-20′,'34′,'34′,'34′,'new notes',”,”,'2008-10-06′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,'Steve',”);
insert into production values(”,'2008-10-21′,'12′,'12′,'12′,'even newer notes',”,”,'2008-10-07′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,'mark',”);
insert into production values(”,'2008-10-22′,'1′,'0′,'0′,”,”,”,'2008-10-08′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”,”);
insert into production values(”,'2008-10-23′,'2′,'0′,'0′,”,”,”,'2008-10-09′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”,”);
insert into production values(”,'2008-10-24′,'3′,'0′,'0′,”,”,”,'2008-10-10′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”,”);
insert into production values(”,'2008-10-15′,'0′,'0′,'0′,'later',”,”,'2008-10-11′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”,”);
insert into production values(”,'2008-10-16′,'0′,'0′,'0′,'later still',”,”,'2008-10-12′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”,”);
insert into production values(”,'2008-10-17′,'0′,'0′,'0′,'later still',”,”,'2008-10-13′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”);
insert into production values(”,'2008-10-18′,'0′,'0′,'0′,'later still',”,”,'2008-10-14′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”);
insert into production values(”,'2008-10-19′,'0′,'0′,'0′,'latest',”,”,'0000-00-00′,'0000-00-00′,'0000-00-00′,”,”,”,”,”,”);
insert into production values(”,'2008-10-01′,'34′,'34′,'34′,'very latest',”,”,'2008-10-02′,'2008-10-04′,'2008-10-04′,”,”,”,”,”,'bruce');
insert into production values(”,”);
It says it's inserting 20 records, but only the first one makes it into the database. Herhangi bir düşünce?
it did not insert into the database table where i want it inserted..:(
Nice work chief
Merhabalar,
I made a minor change to your code, so it works as a CSV importer, as it should.
CSV-s first line should hold the COLUMN NAMEs you want to import, so change the FOREACH loop:
foreach(split($lineseparator,$csvcontent) as $line) {
$ Hatları + +;
$line = trim($line,” \t”);
$line = str_replace(“\r”,”",$line);
/*get COLUMN NAMEs from first line of CSV */
if($lines==1) {
$columns=explode($fieldseparator,$line);
$columnsql=implode(“,”,$columns);
echo $columnsql;
continue;
}
/************************************
Bu hat özel karakter kaçar. girişleri zaten csv dosyasında kaçtı varsa çıkarın
************************************/
$line = str_replace(“'”,”\'”,$line);
/*************************************/
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$linemysql = implode(“','”,$linearray);
if($addauto)
$query = “insert into $databasetable ($columnsql) values('$linemysql');”;
başka
$query = “insert into $databasetable ($columnsql) values('$linemysql');”;
$queries .= $query . “\n”;
@ Mysql_query ($ sorgu);
}
How large is the file you're trying to import?
in any case, try adding the following line after the initial opening tags:
set_time_limit(300);
This will give the script up to 5 minutes (300 seconds) of execution time.
Replacing 300 with 0 will allow it to take as much time as needed.
Hi there, nice script thanks. When running it I get:
Fatal error: Maximum execution time of 30 seconds exceeded in on line 63
Is there anything I can do to get around this?
Robbie, thanks for you addition, it's quite welcome. Unfortunately, it doesn't work straight away when I copy it. I think something is missing because the code is spread out over two posts.
Could you check the code as displayed here? Is something missing?
brad, if you had downloaded it earlier than last week, replace the '< ?'at the top with '< ?php' (remove space)
i get the first so much of it cut off and the rest just code in my browser. I know php is working because the rest of the site works.
I did upgrade to php5 does that matter?
)
; // skip because it falls within the bad array elements
başka
$newarray[$y] = str_replace('”',”,$linearray[$y]);
$linearray = array_values($newarray); // reset the keys to the new array
$x++;
}
}
}
Well, here's the fix to my previous comment:
insert this in between:
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
… insert code snippet below….
$linemysql = implode(“','”,$linearray);
Finds and keeps all “Stuff, More Stuff” together before imploding it.
$a = “”;
$b = “”;
$qoutecount = 0;
for ($x = 0; $x -1) {
$qoutecount++;
if ($qoutecount == 1)
$a = $x; // store the first instance
elseif ($qoutecount == 2) {
$quotecount = 0;
$b = $x; // store the second instance
// THAT DOES IT… compile all elements from $a to $b into $a and ignore elements anything after $a to $b in new array;
$newa = “”; // initialize new string.
for ($z = $a; $z $a && $y
Doesn't account for fields such as this line:
Fname, Lname, “Company, Inc”, City, State, Zip
Company and Inc get split into two different columns.
Rengaraj,
the csv file should be in the same place as the PHP file.
Also, you don't really have to use the same csv file name.
bbqrest.csv is an example, replace this file name with your own.
Can any one reply fast i have a csv file bbqrest.csv at correct path(root)..
I am getting this error File not found. Make sure you specified the correct path.
it would be a good idea to add prevent headers within the csv from being submitted into the database. Or to create a script that pulls out the first row and creates a db using these values as the column names.
Steve,
You would place this script into a web-accessible folder, after changing the variables that need to be changed. Read the comments in the script to find out what you need to specify. Then, call the script up in a web browser, like:
https://www.example.com/path-to-script/simplescvimport.php
Total newbie – tearing my hair out trying to import Excel csv into phpMyAdmin (on a Mac). Would love to know exactly where and what I do with this php script…?
Wow is cool … had idea after read your coding… thank a lot
Hi there, a small modification for auto incrementing values in column 1 (id field)
see variable $count.
ola, enrico.
//$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
//@mysql_select_db($databasename) or die(mysql_error());
$ Lines = 0;
$ Sorgu = "";
$linearray = array();
$count = 0;
foreach(split($lineseparator,$csvcontent) as $line) {
$count = $count + 1;
$ Hatları + +;
$line = trim($line,”\t”);
$line = str_replace(“'”,”\'”,$line);
$ Linearray = ($ fieldseparator, $ line) patlayabilir;
$linemysql = implode(“','”,$linearray);
$query = “insert into `your db table` VALUES('$count','$linemysql');”;
$queries .= $query . “\n”;
@ Mysql_query ($ sorgu);
}
//@mysql_close($con);
Thanks a lot this saved lots of time! Nice script.
I usually use phpmyadmin, but true, in case one does not have it installed, and does not have shell access (like most of the shared hosting providers), this can come in very handy.
Very useful, thank you.