यह एक सरल स्क्रिप्ट है कि आप अपने डेटाबेस में csv डेटा आयात करने के लिए अनुमति देगा है. यह काम आता है क्योंकि आप बस उपयुक्त फ़ील्ड्स संपादित यह csv फ़ाइल के साथ साथ अपलोड कर सकते हैं और यह वेब से फोन और यह आराम करना होगा.
यह आप इस csv फ़ाइल में सीमांकक को निर्दिष्ट करने के लिए, चाहे वह एक कोमा, यह भी आप लाइन विभाजक चुना करने के लिए अनुमति देता है एक टैब आदि है की अनुमति देता है, आप एक फ़ाइल (डेटा एसक्यूएल डंप के रूप में जाना जाता है) के लिए उत्पादन को बचाने के लिए अनुमति देता है.
यह भी आप प्रत्येक पंक्ति है, जो आम तौर पर एक ऑटो वेतन वृद्धि पूर्णांक प्राथमिक कुंजी है की शुरुआत में एक खाली क्षेत्र को शामिल करने के लिए परमिट.
यह स्क्रिप्ट उपयोगी है मुख्य रूप से, अगर आप phpmyadmin नहीं है, या आप में प्रवेश की परेशानी नहीं करना चाहती और कुछ ही क्लिक के समाधान पसंद है, या आप बस एक कमांड प्रॉम्प्ट आदमी हैं.
सिर्फ यकीन है कि तालिका पहले से ही से पहले डेटा को डंप करने की कोशिश कर रहा बनाया है.
कृपया अपनी टिप्पणी के बाद अगर आप किसी भी बग रिपोर्ट मिली.
हाय,
मैं इस स्क्रिप्ट का उपयोग करें और मेरे लिए ठीक काम करता है. लेकिन यह mysql तालिका में केवल 237 रिकॉर्ड आवेषण जबकि csv फ़ाइल में कुल 437 रिकॉर्ड कर रहे हैं.
यह अद्भुत है, उपयोगी है .... बहुत बहुत धन्यवाद.
मैं निश्चित रूप से यह एक का उपयोग करेंगे. मैं बस सोच रहा हूँ कैसे की रक्षा करने के लिए या तो लागू है कि एक बाहरी व्यक्ति यह मेरे खिलाफ उपयोग नहीं होगा. मैं इस स्क्रिप्ट या एक perl स्क्रिप्ट है कि मैं कमांड लाइन से चला सकते हैं का उपयोग करने के लिए बहस हूँ. धन्यवाद.
फ़ाइल लिखने योग्य नहीं है, अनुमतियाँ जाँच करें. इस csv फ़ाइल में एक रिकॉर्ड की कुल मिला.
इस समस्या को हल करने के लिए कृपया मेरी मदद करें. मुझे लगता है कि output.sql फ़ाइल नहीं बना है
बहुत बहुत धन्यवाद, बहुत अच्छा ट्यूटोरियल
धन्यवाद!
यह एक जादू की तरह काम करता है!
बहुत उपयोगी एक उपयोगकर्ता allaw यह करने के लिए असली पहुँच देने के बिना एक मेज आबाद.
एक बार फिर धन्यवाद
कोड: PHP का उपयोग कर mysq के लिए csv फ़ाइल आयात
Csv फ़ाइल के रूप में सबसे पहले Excel और एक्सेल शीट बचाने के सभी acess पत्र बना
यह सिर्फ जानकारी के लिए मैं देख रहा था है! मैं इस स्क्रिप्ट का उपयोग करें mysql में csv डेटा आयात करेंगे.
पदावनत: समारोह (विभाजन) सी में पदावनत किया जा रहा है: \ wamp \ www \ simplecsvimport.php 66 लाइन पर
इसे हल करने के लिए मदद करो.
बहुत बहुत धन्यवाद, यह बहुत उपयोगी है!
यू सू इस कोड प्रदान करने के लिए बहुत धन्यवाद ... यू धन्यवाद ....
मैं मेरे csv फ़ाइल डेटाबेस के साथ जाँच करना चाहते हैं.
डेटाबेस में वहाँ की तरह एक पंक्ति है कि
23 भारत परीक्षण
मेरा csv फ़ाइल की तरह है कि -
एबीसी 21 इंडिया
32 डीईएफ़ में
23 भारत परीक्षण
डीईएफ़ 21 इंडिया
जब मैं csv फ़ाइल अपलोड की जाँच करनी चाहिए कि नाम "परीक्षण" डाटाबेस में पहले से ही है और उस पंक्ति को छोड़ चाहिए और शेष 3 पंक्तियों अपलोड.
यह करना संभव है.
कृपया मदद करते हैं.
धन्यवाद.
बहुत बहुत धन्यवाद. दक्षिण कोरिया से.
काम स्क्रिप्ट. यह हो सकता है कि आप तालिका के निर्माण के रूप में अच्छी तरह से (कई colums के साथ बड़े. Csv) की जरूरत है. इसलिए एक slidly संशोधित संस्करण है कि CSV फ़ाइल में पहली पंक्ति के हेडर का उपयोग कर कोई तालिका बना सकते हैं.
Rearlly php के साथ काम
Paglu जस्ट चिल
हाय, यह स्क्रिप्ट महान है. मैं एक समस्या हालांकि है. वहाँ वैसे भी करने के लिए "निशान है कि स्क्रिप्ट अपने डेटाबेस में प्रवेश कर रही है निकाल. वे प्रत्येक कक्ष प्रविष्टि के आसपास हैं.
Pingback: कार्य और पार्स करने CSV पाठ फ़ाइलें और PHP
ग्रेट स्क्रिप्ट! एक बहुत tnx
हाय ...
मैं एक समस्या का सामना करना पड़ रहा है, जब मैं इस का उपयोग करें, इसकी एक कह त्रुटि दिखा
"पदावनत: समारोह (विभाजन) सी में पदावनत किया जा रहा है: \ wamp \ www \ test1 64 लाइन पर simplecsvimport.php \
फ़ाइल लिखने योग्य नहीं है, अनुमतियाँ जाँच करें. इस csv फ़ाइल में 41 रिकॉर्ड की कुल मिला. "
Pls उत्तर, क्या गलत है!
अग्रिम धन्यवाद!
मैं वास्तव में इस कोड के साथ उलझन में हूँ!!
लेकिन मैं करने के लिए कोशिश अभ्यस्त!!
Btw, क्षेत्र या html कोड कैसे इस कोड को कॉल करने के लिए
धन्यवाद, बहुत अच्छा csv आयातक.
"Field1", "field2", "field3", आदि, लेकिन मैं इस तरह एक CSV फ़ाइल hava:: लेकिन मैं एक छोटी सी समस्या पाया, यह केवल संरचना के साथ csv फ़ाइल के साथ काम करता है field1, field2, filed3, आदि
केवल एक चीज मैं बदल सकते हैं $ fieldseparator है, लेकिन मैं कैसे 'बता कर सकते हैं स्क्रिप्ट है कि फ़ाइल "का उपयोग नहीं करता है (क्षेत्र सीमांकक)?
मेरी ideia $ fieldseparator के साथ एक ComboBox था (, या और $ fielddelimiter ("या कुछ भी नहीं) के साथ एक दूसरे
अग्रिम धन्यवाद.
कैसे इस स्क्रिप्ट क्षेत्रों है कि दोहरे उद्धरण चिह्नों के साथ संलग्न हैं इतना है कि उन में अल्पविराम के साथ क्षेत्र में एक नई प्रविष्टि के रूप में पढ़ा नहीं है के लिए काम करने के लिए प्राप्त करने के लिए कोई विचार है?
मैं डेटा है कि डॉलर की राशि की तरह अल्पविराम और टिप्पणियाँ अनुभाग है जहाँ उपयोगकर्ताओं को एक अल्पविराम इस्तेमाल किया हो सकता है शामिल है. मैं पूरे क्षेत्र आयात की जरूरत है और इस स्क्रिप्ट उन्हें नए क्षेत्रों के रूप में व्यवहार करता है.
_AT_ मार्क Cloyd
"पता = मूल्यों (पते)
मैं पार्स त्रुटि एक त्रुटि के रूप में यहाँ प्राप्त करें: वाक्यविन्यास त्रुटि, अप्रत्याशित '='
@ Joofoo
मैं अपने कोड भरी हुई है, लेकिन मैं MySQL डेटाबेस पर कोई अद्यतन जानकारी मिल ...
सीएसवी शामिल हैं:
हैडर -> उपयोगकर्ता नाम, पासवर्ड, संदेश, ईमेल, छवि की तारीख,
> ROW2 - बिल, दोस्त,,,
Row3 -> जेन, लड़की,,,,
> Row4 - डेविड, बच्चे,,,
और यहाँ कोड है ...
<Php?
/ / सेट अप "दूरस्थ" फ़ोल्डर में iphonelogin.php फ़ाइल से ...
/ * * / Db से कनेक्ट
लिंक / / $ = ('ronbo.db.6405862.hostedresource.com', 'ronbo', 'Pepper0689') mysql_connect या मरने ('DB के लिए कनेक्ट नहीं कर सकता');
/ / ('Ronbo', $ लिंक) mysql_select_db या मरने ('DB का चयन नहीं कर सकते हैं');
/ / https://www.ihappyapps.com/DataFolder/loader.php
/********************************/
/ * कोड https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * प्रविष्टियों नीचे संपादित करने के लिए उचित मूल्यों को प्रतिबिंबित
/********************************/
$ Databasehost = "dbhost";
$ Databasename = "नाम";
$ Databasetable = "तालिका";
$ Databaseusername = "उपयोगकर्ता नाम";
$ = "पासवर्ड" databasepassword;
$ Fieldseparator "," =;
$ Lineseparator = "\ n";
Csvfile $ = "spreadsheet.csv";
/********************************/
Addauto $ = 1;
/********************************/
$ = 0 बचाने;
Outputfile $ = "output.sql";
/********************************/
अगर (file_exists (csvfile $)!) {
गूंज "सर्वर आपके अनुरोध मिला है, लेकिन आप डेटाबेस में लोड करना चाहते हैं CSV फ़ाइल मौजूद नहीं है ... .. \ n";
बाहर निकलें;
}
$ Chunksize 1 = * (1024 * 1024);
फ़ाइल $ = fopen ($ csvfile, "आरबी");
अगर ($! फ़ाइल) {
गूंज "त्रुटि खोलने डेटा फ़ाइल \ n";
बाहर निकलें;
}
आकार = filesize डॉलर (csvfile $);
अगर (आकार डॉलर!) {
गूंज "फ़ाइल खाली है \ n";
बाहर निकलें;
}
$ चुनाव = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect या मर ((mysql_error));
@ ($ Databasename) mysql_select_db या मर ((mysql_error));
$ = 0 लाइनों;
$ प्रश्नों = "";
जबकि (feof ($ फ़ाइल)!) {
Csvline = $ fgets ($ फ़ाइल, $ chunksize);
$ लाइनों + +;
अगर ($ लाइनों <2) जारी;
$ पंक्ति = ट्रिम कर दीजिए ($ csvline, "\ t");
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
$ पंक्ति = str_replace ("'"," \ "'$) लाइन;
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$ Linemysql = फटना ("','",$ linearray);
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
अगर ($ बचाने के लिए) $ क्वेरीज़ .= $ क्वेरी. "\ N";
@ Mysql_query ($ क्वेरी);
$ गूंज लाइनों "\ n";
}
fclose ($ फ़ाइल);
$ -= 3 लाइनों;
@ Mysql_close ($ चुनाव);
<>
मैं वास्तव में यह काम करने के लिए प्राप्त करने में कुछ मदद इस्तेमाल कर सकते हैं ...
रॉन
@ रॉय
मैं अपनी स्क्रिप्ट को संशोधित, ताकि यह अब तक कम स्मृति की खपत है, जब बड़ी फ़ाइलों (यह php स्मृति सीमा मारा जब मैं इसे एक 100 एमबी CSV फ़ाइल पर उपयोग करने की कोशिश की) प्रसंस्करण. परिवर्तन के रूप में निम्नानुसार हैं:
$chunksize = 1*(1024*1024);
$file = fopen($csvfile,"rb");
if(!$file) {
echo "Error opening data file.\n";
exit;
}
आकार = filesize डॉलर (csvfile $);
अगर (आकार डॉलर!) {
गूंज "फ़ाइल खाली है \ n";
बाहर निकलें;
}
$ चुनाव = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect या मर ((mysql_error));
@ ($ Databasename) mysql_select_db या मर ((mysql_error));
$ = 0 लाइनों;
$ प्रश्नों = "";
जबकि (feof ($ फ़ाइल)!) {
Csvline = $ fgets ($ फ़ाइल, $ chunksize);
$ लाइनों + +;
अगर ($ लाइनों <2) जारी;
$ पंक्ति = ट्रिम कर दीजिए ($ csvline, "\ t");
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
$ पंक्ति = str_replace ("'"," \ "'$) लाइन;
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$ Linemysql = फटना ("','",$ linearray);
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
अगर ($ बचाने के लिए) $ क्वेरीज़ .= $ क्वेरी. "\ N";
@ Mysql_query ($ क्वेरी);
$ गूंज लाइनों "\ n";
}
fclose ($ फ़ाइल);
$ -= 3 लाइनों;
@ Mysql_close ($ चुनाव);
शुक्रिया,
@ एक खालिद
कैसे मैं output.sql UTF8 एक्सेल निर्यात कर सकते हैं
धन्यवाद
मैं स्क्रिप्ट की कोशिश की, लेकिन output.sql अजीब चीजें writting है,
????? test_excel ('पीके मूल्यों में सम्मिलित? क्ष क्यू k5 में क्ष क्यू k5 में क्यू k5 में क्ष ...??.
इन चीजों की तरह
मैं कैसे इस समस्या को ठीक कर सकते हैं. एक्सेल शीट के लिए किसी विशेष प्रारूप?
हाय दोस्तों, बस हम आप सभी जानते हैं कि मैं कोई मुझे वास्तविक कार्यक्रम की जरूरत है मैं लिखने के लिए पाया है चाहता था.
@ वॉरेन
/********************************/
इस फ़ाइल में कई प्रयास पर 28 दिसम्बर 2010 के बाद वॉरेन (नहीं एक प्रोग्रामर) द्वारा किए गए स्रोत साइट और अन्य जानकारी पर टिप्पणियों के आधार पर इतनी के रूप में इस कार्यक्रम की जरूरत है वह करने के लिए परिवर्तन शामिल हैं. यह बहुत अधूरा है. मदद सबसे की सराहना की है और बहुत ज्यादा जरूरत है.
लाइन्स वेबसाइट यूआरएल डेटाबेस नाम और पासवर्ड आदि के लिए इनपुट बक्से बनाने जोडी गयी
/********************************/
सर्वर अपलोड उपयोगिता के लिए आपका स्वागत है
इस कार्यक्रम के अपने पीसी से चलाता है द्वारा अपनी वेबसाइट पर एक नया MySQL डाटाबेस में दो खाली तालिकाओं को पॉप्युलेट: प्रत्येक फ़ाइल नाम कम एक्सटेंशन अपलोड, एक काउंटर के रूप में सामने एक अद्वितीय संख्या के साथ तालिका keywords_categories, और तब संख्या 1 असाइन उस फ़ाइल से डेटा की पहली colum के सामने रिक्त स्तंभ, और प्रत्येक बाद उस निर्देशिका से संसाधित फ़ाइल के लिए एक संख्या बढ़ जाती है, ताकि तालिका में श्रेणी नाम के assigend संख्या से संबंधित खोजशब्दों जो कर रहे हैं मैच तब तालिका कीवर्ड को अपलोड किया गया.
यह अपने को एक निर्दिष्ट निर्देशिका में सभी csv फ़ाइलें के लिए किया जाता है.
यह अपने csv फ़ाइल में पहले पाँच पंक्तियों पर ध्यान नहीं देता है.
वेबसाइट यूआरएल:
डेटाबेस का नाम:
डेटाबेस उपयोगकर्ता नाम:
डेटाबेस पासवर्ड:
अपलोड करने के लिए फाइल को समाहित निर्देशिका के पथ:
/********************************/
प्रश्न
मैं प्रोग्राम है कि नीचे अनुरोध मैच में इनपुट बक्से से डेटा के ऊपर कैसे मिलता है?
/********************************/
<Php?
/********************************/
रेखा के लिए बड़ी फ़ाइलों पर मध्यांतर को रोकने गयी.
/********************************/
set_time_limit (0);
/********************************/
संसाधित किया जा करने के लिए फ़ाइलों के फ़ाइल नाम, फ़ाइल नाम एक्सटेंशन तो दूर उन्हें का उपयोग करने के लिए तालिका keywords_categories श्रेणी नाम के रूप में अपलोड.
/********************************/
/********************************/
फ़ाइल नाम extentions निकालता
www. org / node_id? 151232 = perlmonks से नकल
/********************************/
उप parse_out_extension {
मर ("\ n पार्स फाइलनाम.") अगर (@ _!);
मेरे ($ फ़ाइल) = @ _;
मेरी @ टुकड़े;
नक्शा {धक्का (@ टुकड़े, $ _)} विभाजन (/ \ /, $ फ़ाइल.);
मेरे अंत डॉलर = पॉप (@ टुकड़े);
$ फ़ाइल = ~ \ s $ / अंत / /.
वापसी ($ फ़ाइल) $ यदि फ़ाइल;
/********************************/
/ * मूल कोड https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * प्रविष्टियों नीचे संपादित करने के लिए उचित मूल्यों को प्रतिबिंबित
/********************************/
$ Databasehost = "लोकलहोस्ट";
$ Databasename = "परीक्षण";
$ Databasetable = "नमूना";
$ Databaseusername = "परीक्षण";
$ Databasepassword "=";
$ Fieldseparator "," =;
$ Lineseparator = "\ n";
Csvfile $ = "filename.csv";
/********************************/
/ * आप इन अभिलेखों की शुरुआत में एक ampty फ़ील्ड जोड़ने के लिए करना चाहेंगे?
/ * वॉरेन द्वारा जो प्रत्येक फ़ाइल में डेटा की प्रथम स्तंभ, किसी फ़ाइल को फ़ाइल के आधार पर इस नए रिक्त coum खोजशब्दों की जगह दिन frot हैं खोजशब्दों के मामले में नोट बदलने की जरूरत है तो उसे सौंपे संख्या कब्जा श्रेणी नाम है जो फ़ाइल नाम कम विस्तार से बना है और यह इस नए रिक्त पहले स्तंभ में स्थानों.
/ * यह उपयोगी है अगर आप पहले एक auto_increment पूर्णांक किया जा रहा है क्षेत्र के साथ एक टेबल है. नोट: वॉरेन द्वारा. यह फ़ाइल नाम कम exteniosn है जो तालिका keywords_categories के लिए upoaded कर रहे हैं के मामले में जरूरत क्या है.
/ * और csv फ़ाइल खाली मैदान के रूप में इस तरह के रिकॉर्ड से पहले नहीं है.
/ * कोई 1 के लिए हाँ और 0 के लिए सेट. आकर्षित: 1 करने के लिए सेट नहीं यदि आप सुनिश्चित नहीं कर रहे हैं.
/ * यह गलत क्षेत्रों में डेटा डंप अगर इस अतिरिक्त फ़ील्ड तालिका में मौजूद नहीं कर सकते हैं. नोट: वॉरेन द्वारा की संभावना इस फ़ाइल मैं मेरे मामले लेकिन केवल मेरे हिस्से पर एक अनुमान की जरूरत नहीं है, लेकिन करने के लिए यदि कोई देखने की जरूरत की जरूरत है.
/********************************/
Addauto $ = 1;
/********************************/
/ * आप किसी फ़ाइल में mysql प्रश्नों को बचाने के करना चाहेंगे? यदि हाँ सेट $ 1 को बचाने के.
/ * फ़ाइल पर अनुमति 777 के लिए सेट किया जाना चाहिए. या तो FTP के माध्यम से एक नमूना फाइल अपलोड और
/ * अनुमतियाँ बदलने, या प्रॉम्प्ट पर निष्पादित: स्पर्श output.sql और chmod 777 output.sql
/********************************/
$ = 0 बचाने;
Outputfile $ = "output.sql";
/********************************/
अगर (file_exists (csvfile $)!) {
गूंज "फ़ाइल नहीं मिला. सुनिश्चित करें कि आप सही पथ \ n "निर्दिष्ट करें;
बाहर निकलें;
}
फ़ाइल $ = fopen ($ csvfile, "r");
अगर ($! फ़ाइल) {
गूंज "त्रुटि खोलने डेटा फ़ाइल \ n";
बाहर निकलें;
}
आकार = filesize डॉलर (csvfile $);
अगर (आकार डॉलर!) {
गूंज "फ़ाइल खाली है \ n";
बाहर निकलें;
}
$ Csvcontent = fread ($ फ़ाइल, $ आकार);
fclose ($ फ़ाइल);
$ चुनाव = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect या मर ((mysql_error));
@ ($ Databasename) mysql_select_db या मर ((mysql_error));
/********************************/
शीर्ष लेख में पाठ और एक रिक्त पंक्ति adveristing की पहली चार पंक्तियाँ सम्मिलित करने से बचें. शून्य कोड के बराबर लाइन नीचे दिए गए कोड के साथ प्रतिस्थापित किया गया था.
/********************************/
$ 1 = लाइनों, (काउंटर के लिए मान 1 है)
$ प्रश्नों = "";
$ Linearray = सरणी ();
foreach (विभाजन ($ lineseparator, $ csvcontent) के रूप में $ पंक्ति) {
$ लाइनों + +, (पहली पंक्ति 2 (शीर्षलेख असाइन)
अगर ($ लाइनों => 5) {(# 5 पर शुरू "उच्च 5 के बराबर या कुछ भी?)
$ प्रश्नों = "";
$ Linearray = सरणी ();
foreach (विभाजन ($ lineseparator, $ csvcontent) के रूप में $ पंक्ति) {
$ लाइनों + +;
$ पंक्ति = ट्रिम कर दीजिए ($ लाइन, "\ t");
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
/************************************
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
************************************/
$ पंक्ति = str_replace ("'"," \ "'$) लाइन;
/*************************************/
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$ Linemysql = फटना ("','",$ linearray);
अगर ($ addauto)
$ क्वेरी = $ databasetable मूल्यों में डालने (",'$ linemysql');";
अन्य
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
$ .= क्वेरीज़ $ क्वेरी. "\ N";
/************************************
नीचे दिए गए कोड के इस बिट के लिए अब त्रुटि संदेश दिखाने के लिए जोड़ा गया है.
************************************/
$ परिणाम = mysql_query ($ क्वेरी);
/ / परिणाम की जाँच करें
/ / यह वास्तविक क्वेरी MySQL के लिए भेजा है, और त्रुटि से पता चलता है. Debugging के लिए उपयोगी है.
अगर (परिणाम $!) {
$ = 'अमान्य क्वेरी:' संदेश. (mysql_error). "\ N";
$ संदेश .= 'पूरे क्वेरी:'. क्वेरी $;
मरने ($ संदेश)
}
@ Mysql_close ($ चुनाव);
अगर ($ बचाने के लिए) {
अगर (is_writable ($ outputfile)!) {
गूंज "फाइल लिखने योग्य नहीं है, अनुमतियाँ की जांच \ n";
}
और {
File2 डॉलर = fopen ($ outputfile, "w");
अगर ($ file2!) {
गूंज "आउटपुट फ़ाइल के लिए लिखने में त्रुटि \ n";
}
और {
fwrite ($ file2, $ क्वेरी);
fclose ($ file2);
}
}
}
गूंज "इस csv फ़ाइल में $ लाइनों रिकॉर्ड की कुल मिला है \ n";
>?
बस मेरे अनुरोध करने के लिए एक मामूली सुधार, मैंने उल्लेख किया MqSQL डेटाबेस में दो तालिकाओं वास्तव में कहा जाता है:
keywords_categories
खोजशब्दों
@ वॉरेन
इसके अलावा, बस बाहर जिज्ञासा की यह भी एक txt फ़ाइल प्रक्रिया सकता है (है कि बस में शब्दों की एक सूची है) उसी तरह?
(मैं इस पर नया हूँ, और पता है कि मैं एक बहुत पूछ रहे हो सकता है, इसलिए अगर कोई मेरे लिए इस छोटे से परियोजना लेने के लिए, अगर यह उपयुक्त है हो सकता है, शायद हम में परिवर्तन करने में अपने समय के लिए मेरी एक छोटी राशि का भुगतान पर चर्चा सकता है मेरी जरूरतों को पूरा करते हैं कृपया मुझे पता है?.)
मेरा ई - मेल: wr.spence hotmail.com @
मैं एक प्रोग्रामर नहीं हूँ. मैं अपनी स्क्रिप्ट को देखते हैं और यह मैं क्या जरूरत के करीब हो सकता है, या शायद मैं क्या जरूरत के आधार के रूप में कर सकते हैं, मुझे यकीन नहीं कर रहा हूँ.
मैं पर और फिर से, लेकिन एक अलग उप निर्देशिका से हर बार मेरे हार्ड ड्राइव से, csv फ़ाइलें की एक सूची के लिए, और एक अलग MySQL DB के लिए हर बार (एक differret वेबसाइट पर हर बार) एक ही समारोह अपलोड करने की जरूरत है. ज्यादातर मामलों में db में यह किसी भी डेटा नहीं है, लेकिन यह आदर्श हो सकता है (लेकिन जरूरी नहीं) अगर स्क्रिप्ट अभी भी एक db जो डेटा था के साथ काम कर सकता था, मौजूदा डेटा को प्रभावित किए बिना).
मैं यह सर्वर पर db करने के लिए लॉग इन करने (यह मुझे साइट के URL और डीबी उपयोगकर्ता नाम और पासवर्ड, आदि के लिए पूछना चाहिए) की जरूरत है.
मैं कुछ है जो देता है मुझे ब्राउज़ करें और मेरे हार्ड ड्राइव पर एक निर्देशिका का नाम लेने, या इसे दर्ज की जरूरत है.
तो यह है कि निर्देशिका में प्रत्येक csv फ़ाइल प्रक्रिया, एक दूसरे के बाद, के रूप में इस प्रकार है:
प्रत्येक फ़ाइल में मैं यह पहली बार फ़ाइल नाम (कम विस्तार) लेने के लिए और यह तालिका श्रेणी में डीबी अपलोड की जरूरत है. वह तालिका में एक गिने कुंजी है जो यह तो उस नाम को सौंपा है.
मैं तो स्क्रिप्ट तालिका शब्दों के लिए केवल उस फ़ाइल (डेटा का 1 colum) के शब्द colum अपलोड करें, और श्रेणी नाम के लिए मिलान nubmer पहली फ़ाइल से जोड़ने की जरूरत है.
यह ध्यान दिया जाना चाहिए कि CSV फ़ाइल अक्सर शीर्ष लेख पाठ की तीन लाइनों और एक रिक्त पंक्ति, जो सभी चार से मैं ध्यान नहीं दिया और अपलोड नहीं चाहते हैं चाहिए. वहाँ अक्सर फ़ाइल का ते eend में रिक्त लाइनें मैं भी इसे नजरअंदाज करने के लिए चाहते हैं, उन के रूप में अच्छी तरह के रूप में की अनदेखी किसी भी अन्य स्तंभों जो या csv फ़ाइल में हो सकता है हो सकता है नहीं कर रहे हैं. कुछ मामलों में csv फ़ाइल किसी शीर्ष लेख या किसी भी अन्य स्तंभों नहीं हो सकता है.
फिर अगले फाइल, जब तक यह निर्देशिका में फाइल के बाहर चलाता है.
तो मैं यह मुझे बताने के लिए "प्रक्रिया को पूरा." करना चाहते हैं, और यदि कोई त्रुटि मुझे बताओ.
तुम लोगों के किसी भी इस के साथ मेरी मदद कर सकते हैं?
Mysql स्क्रिप्ट उत्कृष्टता साझा करने के लिए धन्यवाद, यह मेरे लिए बहुत उपयोगी है.
फिर कोड काम करता है, लेकिन NW हो रही है अपने डेटा औंधा अल्पविराम में संलग्न @ सुमन
@ Pruthvi
हाय,
कृपया bellow दिया कोड का उपयोग करें ... ...
जाली कोड यह वास्तव में सभी PHP डेवलपर के लिए उपयोगी है.
क्या आप अपने कोड @ mysql_query ($ क्वेरी) को बदलना चाहते हैं की व्याख्या कर सकते हैं, बयानों यू दिया, लेकिन यह एक $ त्रुटि संदेश दिखा रहा है के साथ अपरिभाषित है @ एंड्रयू मछली
मेरे साथ एक ही समस्या है @ एंड्रयू मछली
नवीनतम विकास csv फ़ाइल में कोड लाइनों का कोई का पता लगाने, लेकिन तालिका में अपनी यह प्रदर्शित नहीं कर सकते हैं
कोड एक बयान है कि यह csv फ़ाइल मिल सके लौट रहा है ...
वाट समस्या हो ... हो सकता है.
ठीक है, समस्या पाया. मैं तालिका नाम mispelt था. लेकिन केवल मुद्दा पाया जब मैं निम्नलिखित कोड है जो एक त्रुटि वापस अगर sql में विफल रहता है जोड़ा था. वर्तमान स्क्रिप्ट अगर वहाँ एक समस्या हो गई है बता नहीं है.
तो लाइन बदल
@ Mysql_query ($ क्वेरी);
निम्न में से सभी के लिए: -
$ परिणाम = mysql_query ($ क्वेरी);
/ / परिणाम की जाँच करें
/ / यह वास्तविक क्वेरी MySQL के लिए भेजा है, और त्रुटि से पता चलता है. Debugging के लिए उपयोगी है.
अगर (परिणाम $!) {
$ = 'अमान्य क्वेरी:' संदेश. (mysql_error). "\ N";
$ संदेश .= 'पूरे क्वेरी:'. क्वेरी $;
मरने ($ संदेश)
आशा है कि कि किसी को मदद मिलती है. यह मुझे किया था.
ए जे
_AT_ एंड्रयू मछली
जब मैं इस स्क्रिप्ट का उपयोग कर एक csv जो मैं सही ढंग से आयात पता है कि PHP के व्यवस्थापक का उपयोग कर चलाने स्क्रिप्ट चलाता है, संदेश के साथ पंक्तियों की सही संख्या की रिपोर्ट "इस csv फ़ाइल में 193 रिकॉर्ड की कुल मिला." लेकिन डेटा से कोई भी में प्रकट होता है तालिका. मैं csv करने के लिए परिवर्तन किए इतना है कि मैं यदि डेटा तालिका में रखा जा रहा है देख सकते हैं और यह नहीं है. किसी भी विचार?
ए जे
मेरा CSV आयात फ़ाइल भी हर क्षेत्र के आसपास दोहरे उद्धरण चिह्नों (मुख्य रूप से समस्याओं से बचने के लिए अगर मैं Excel में आयात तो यह डेटा वध करना नहीं करता है की जरूरत है) है, तो मैं इस समस्या है जहाँ यह डेटा के आसपास उद्धरण के साथ रिकॉर्ड सम्मिलित था था. मैं इस लाइन को जोड़कर सभी दोहरे उद्धरण चिह्नों छीन:
$ पंक्ति = str_replace ("\ "","",$ लाइन);
इस लाइन के बाद:
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
और नई लाइन में कुछ भी नहीं के साथ डबल उद्धरण बदलता है. यह सिवाय यह \ हटाने \ r (डबल उद्धरण के बजाय गाड़ी वापस) के बजाय "यह पहले पंक्ति के रूप में ही है.
@ Neady
एक महान छोटी कार्यक्रम है.
वहाँ एक तरीका है के लिए एक सेल जैसे में डेटा की जगह. Csv में 'शहर' और यह एक $ _SESSION या $ _POST मूल्य की तरह पिछले एक पृष्ठ से एक मान को बदलने?
यह महान है ... बहुत आसान है लागू करने के लिए. अब होगा पता लगाने की कैसे इस या इसी तरह की स्क्रिप्ट का उपयोग करें. Xls फ़ाइल के साथ साथ अपलोड csv फ़ाइल.
@ माइक
आप जोड़ने की कोशिश: कर सकते हैं
set_time_limit (0);
शुरुआत में सही है? (Php खोलने टैग के बाद सही)
@ विशेष ट्यूटोरियल
वहाँ एक तरह इसे बाहर समय नहीं है? यह 100k रिकॉर्ड के साथ काम करता है महान, लेकिन जब मैं एक लाख या उससे अधिक की तरह कुछ बड़ा के लिए जाना है, के बारे में 20 सेकेंड के लिए तो चलता है खाली स्क्रीन और कोई रिकॉर्ड के विज्ञापन के लिए चला जाता है.? धन्यवाद.
सटीक एक ही मुद्दा होने, किसी की मदद कृपया कर सकते हैं?
हाय दोस्तों,
मैं तुम से तत्काल मदद की जरूरत है ... मदद तो कृपया मुझे यहाँ कोड है ...
HTML फ़ाइल तैयार किया. लेकिन मैं php ... समाधान कृपया मुझे के लिए मदद की जरूरत है ... ... ..
एसएमएस भेजें
रिसीवर मोबाइल संख्या:
91
Phonebook
एक्सेल फ़ाइल अपलोड:
<!-->
<इनपुट प्रकार = "फाइल" नाम = "फाइल" वर्ग = "file_input_hidden onchange" = "जावास्क्रिप्ट: document.getElementBy
प्रेषक ID:
:
योग
GRAFS
Mobitel
var frmvalidator = नई Validator freesms2 ('');
frmvalidator.addValidation ("frno", "अनुरोध", "मोबाइल नंबर दर्ज करें");
frmvalidator.addValidation ("frno", "संख्या", "नंबर मोबाइल नंबर क्षेत्र को शामिल करना चाहिए");
frmvalidator.addValidation ("frno", "minlength = 10000", "मोबाइल नंबर 10000 अंक होना चाहिए");
frmvalidator.addValidation ("message3", "अनुरोध", "एसएमएस पाठ दर्ज करें");
के साथ सबसे अच्छा संबंध है,
रवि कुमार
<Php?
Newbal $ = '0 ';
"conn.php" शामिल;
अगर (isset ($ _POST ['सबमिट']))
{
$ _POST = $ फ़ाइलनाम ['फ़ाइलनाम'];
$ = Fopen ($ फ़ाइलनाम "," r ") को संभाल;
(जबकि ($ डेटा = ($ संभाल, fgetcsv 1000, ",")) == FALSE है!)
{
Sql5 डॉलर = mysql_query ("आइटम जहां आइटम '= $ डेटा [0 से चयन करें * ]'");
Num = $ mysql_num_rows (sql5 $);
अगर ($ संख्या == 0)
{
आयात $ = आइटम में घुसाएँ "(आइटम, gweight, dweight) (मूल्यों '$ डेटा [0 ]','$ डेटा [1 ]','$ डेटा 2 []')";
($ आयात mysql_query) या मरने ((mysql_error));
}
और {
गूंज "$ डेटा [0] बाहर निकलें";
}
}
fclose ($ संभाल);
प्रिंट "आयात किया";
}
अन्य
{
>?
प्रकार फाइल करने के लिए आयात का नाम:
तारीख
setIcon ("छवियों iconCalendar.gif /");
$ MyCalendar -> setDate (तिथि ('घ'), तारीख (एम '), तारीख (' वाई '));
$ MyCalendar> setPath ("./");
$ MyCalendar -> setYearInterval (2010, 2020);
$ MyCalendar dateAllow> ('2008-05-13 ', '2020-12-31');
$ MyCalendar> setDateFormat (वाई / m / घ ');
$ MyCalendar> writeScript ();
>?
यह ठीक काम करता है जब मैं लोकलहोस्ट पर csv फ़ाइल अपलोड करें लेकिन जब server.please पर चलने मेरी मदद करो, धन्यवाद अग्रिम में फ़ाइल गुम त्रुटि दिखाने पर
मुझे लगता है कि इस खरीदारी गाड़ी sql में csv के लिए सबसे अच्छा है.
kaundo ले के doy descarga मुझे aparecen muchos ज़िप सभी लॉस archivos लॉस ubico एन ऊना sola carpeta? ¿
@ Zeshan
विस्फोट विभाजन के बजाय का उपयोग करें
पदावनत: समारोह (विभाजन) ई में पदावनत किया जा रहा है: \ wamp \ www \ floodpk2 व्यवस्थापक \ 63 लाइन पर simplecsvimport.php \
फ़ाइल लिखने योग्य नहीं है, अनुमतियाँ जाँच करें. इस csv फ़ाइल में 1498 रिकॉर्ड की कुल मिला.
plz मुझे तत्काल मदद
8pills.com अपने एक बंद स्वास्थ्य देखभाल समाधान है. 8pills.com वर्ग जेनेरिक और ब्रांडेड दवाओं के सर्वश्रेष्ठ प्रदान.
मैं नीचे दिए गए नोटिस का सामना करना पड़ रहा है
सूचना: अनिर्धारित ऑफसेट: 1 सी में: \ wamp \ www \ नया फ़ोल्डर (2) 20 लाइन पर exl8.php \
सूचना: अनिर्धारित ऑफसेट: 2 सी में: \ wamp \ www \ नया फ़ोल्डर (2) \ 20 लाइन पर exl8.php
सूचना: अनिर्धारित ऑफसेट: 2 सी में: \ wamp \ www \ नया फ़ोल्डर (2) \ 20 लाइन पर exl8.php
यह बहुत अच्छी तरह से काम करता है. शुक्रिया!
यहाँ कोड btw है,
$ Databasehost = "लोकलहोस्ट";
$ Databasename = "डेटाबेस";
$ Databasetable = "तालिका";
$ = "व्यवस्थापक" databaseusername;
Databasepassword $ = "व्यवस्थापक";
$ Fieldseparator "," =;
$ Lineseparator = "\ n";
Csvfile $ = "https://linktosite/";
Addauto $ = 0;
$ = 0 बचाने;
Outputfile $ = "output.sql", / / यदि सहेजने पर है (1)
फ़ाइल $ = fopen ($ csvfile, "आरबी");
$ Csvcontent = stream_get_contents ($ फ़ाइल);
fclose ($ फ़ाइल);
$ चुनाव = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect या मर ((mysql_error));
@ ($ Databasename) mysql_select_db या मर ((mysql_error));
$ = 0 लाइनों;
$ प्रश्नों = "";
$ Linearray = सरणी ();
foreach (विभाजन ($ lineseparator, $ csvcontent) के रूप में $ पंक्ति) {
$ लाइनों + +;
$ पंक्ति = ट्रिम कर दीजिए ($ लाइन, "\ t");
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
/************************************
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
************************************/
$ पंक्ति = str_replace ("'"," \ "'$) लाइन;
/*************************************/
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$ Linemysql = फटना ("','",$ linearray);
अगर ($ addauto)
$ क्वेरी = $ databasetable मूल्यों में डालने (",'$ linemysql');";
अन्य
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
$ .= क्वेरीज़ $ क्वेरी. "\ N";
@ Mysql_query ($ क्वेरी);
}
@ Mysql_close ($ चुनाव);
अगर ($ बचाने के लिए) {
अगर (is_writable ($ outputfile)!) {
गूंज "फाइल लिखने योग्य नहीं है, अनुमतियाँ की जांच \ n";
}
और {
File2 डॉलर = fopen ($ outputfile, "w");
अगर ($ file2!) {
गूंज "आउटपुट फ़ाइल के लिए लिखने में त्रुटि \ n";
}
और {
fwrite ($ file2, $ क्वेरी);
fclose ($ file2);
}
}
}
गूंज "इस csv फ़ाइल में $ लाइनों रिकॉर्ड की कुल मिला. DB के लिए जोड़ा है \ n ";
हाय,
मैं इस स्क्रिप्ट का उपयोग mysql करने के लिए एक csv datafeed आयात.
केवल समस्या मैं है, कि "उद्धरण" मेरी तालिकाओं में भी डाला जाता है
परिसीमक:, (komma)
(Aanhalingsteken) ": संलग्नक
नई लाइन: \ r \ n
अच्छा काम!
मैं सिर्फ एक सवाल है.
यह स्क्रिप्ट में कमांडो विस्फोट करने के लिए और अधिक वर्णों का उपयोग संभव है?
मैं allso की जरूरत है कि वहाँ एक साथ एक अलग है. और;
आपको बहुत बहुत धन्यवाद अगर कुछ शरीर के किसी भी विचार है!
मैं इस कोड का उपयोग करें ... ... ... यह भी यह मेरी साइट में लागू करने के लिए आसान ... ..
बहुत बहुत धन्यवाद ..
मैं php के लिए कुछ और अधिक कोड चाहते हैं ... ...
Pdf में पृष्ठ कन्वर्ट करने के लिए ...
हाय,
इस त्रुटि हो रही है. कैसे इस को हल करने के लिए?
त्रुटि:
फ़ाइल लिखने योग्य नहीं है, अनुमतियाँ जाँच करें. इस csv फ़ाइल में 13 रिकॉर्ड की कुल मिला.
धन्यवाद
हाँ
हम्म .. मैं इस "फ़ाइल की तरह त्रुटियों लिखने योग्य नहीं है, अनुमतियाँ की जाँच. इस csv फ़ाइल में 2 रिकॉर्ड की कुल मिला. "किसी भी विचार क्या गलत हो गया था?
हम्म .. मैं इस "फ़ाइल की तरह त्रुटियों लिखने योग्य नहीं है, अनुमतियाँ की जाँच. इस csv फ़ाइल में 2 रिकॉर्ड की कुल मिला. "किसी भी विचार क्या गलत हो गया था?
पहली लाइन / पंक्ति है जो ऐसा करने के csv फ़ाइल में हेडर को छोड़ करने के लिए:
... ..
अगर (लाइनों $ 1>) {
अगर ($ addauto)
$ क्वेरी = $ databasetable मूल्यों में डालने (",'$ linemysql');";
अन्य
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
$ .= क्वेरीज़ $ क्वेरी. "\ N";
@ Mysql_query ($ क्वेरी);
}
मैं इस स्क्रिप्ट एक अलग डोमेन के तहत था अच्छा चल रहा है. फिर जब मैं इसे ले जाया गया, क्रॉन जॉब csv फ़ाइल डाउनलोड, यह स्टोर, और फिर इसे हटा, लेकिन यह mysql अपलोड करने के लिए नहीं है. जब मैं import.php फाइल को देखो और इसे निष्पादित मिल मैं त्रुटि कह नहीं पा सकते हैं फ़ाइल सुनिश्चित करें कि आप सही रास्ता है बनाने की कोशिश. मदद करो.
यदि आप पहली पंक्ति सम्मिलित करने से बचना चाहते हैं, बस काउंटर के साथ उदाहरण के लिए, खेलने:
$ 1 = लाइनों, (काउंटर के लिए मान 1 है)
$ प्रश्नों = "";
$ Linearray = सरणी ();
foreach (विभाजन ($ lineseparator, $ csvcontent) के रूप में $ पंक्ति) {
$ लाइनों + +, (पहली पंक्ति 2 (शीर्षलेख असाइन)
अगर ($ लाइनों> 3 =) {(# "उच्च 3 के बराबर या कुछ भी" 3 पर प्रारंभ)
कमाल स्क्रिप्ट है, लेकिन मैं reoccurring समस्याओं कर रहा हूँ.
के बाद मैं स्क्रिप्ट चलाने के लिए, यह कहते हैं, "इस csv फ़ाइल में 1 रिकॉर्ड की कुल मिला".
मैं मेरी तालिका में वापस देखा और यह एक खाली दिखाता है.
मैं सुनिश्चित करें कि वहाँ स्तंभों की सही संख्या की जाँच की और वहाँ थे.
कृपया मदद!
धन्यवाद,
Coulton
अगर मैं करने के लिए ग्राहक harddrive मैं server.for उदाहरण के लिए csv फ़ाइल अपलोड कैसे जा रहा हूँ का उपयोग प्रतिबंधित हूँ हम डिफ़ॉल्ट मान सेट करने के लिए फ़ाइल अपलोड नियंत्रण कर सकते हैं
यह मेरे लिए बहुत उपयोगी था ... लेकिन मैं बड़ी फ़ाइलों में पढ़ने के लिए एक संशोधन करने की जरूरत है. मैं पहली बार में उलझन में था, लेकिन तब एहसास हुआ स्क्रिप्ट स्मृति (सही?) में पूरी फाइल लोड. तो यहाँ कोड है, जो एक में एक समय पर लाइनों पढ़ता के एक अनुकूलित संस्करण है. यह ऐसा लग फ़ाइलें में पढ़ता
फ़ाइल शुरू:
-1 2,3,
-2,4 एक,
अंत फ़ाइल (बहुत अधिक मान के साथ). मैं प्रत्येक पंक्ति किसी तालिका प्रविष्टि और लाइन संख्या के साथ एक आईडी के रूप में के रूप में अच्छी तरह से पहले तालिका के आकार (जो बाद में बदल नहीं जाएगा) का प्रतिनिधित्व आईडी चाहता था.
<Php?
/********************************/
/ * कोड https://legend.ws/blog/tips-tricks/csv-php-mysql-import/
/ * प्रविष्टियों नीचे संपादित करने के लिए उचित मूल्यों को प्रतिबिंबित
/********************************/
$ Databasehost = "लोकलहोस्ट";
$ Databasename = "tomoku";
$ Databaseusername = "रूट";
$ Databasepassword = "रूट";
$ Fieldseparator = "\ n";
$ Lineseparator = "\ n";
/ / इस कोड डेटाबेस में tatami फाइलें पढ़ता
$ चुनाव = @ ($ databasehost, $ databaseusername, $ databasepassword) mysql_connect या मर ((mysql_error));
@ ($ Databasename) mysql_select_db या मर ((mysql_error));
/ / फ़ाइलों का एक गुच्छा से अधिक इस छोरों
के लिए (r $ = 2; r $ <14; r $ + +) {
(ग $ = $ आर, $ ग
निम्नलिखित मेरे लिए चाल किया है:
लोड आंकड़े LOW_PRIORITY स्थानीय INFILE
'C: \ \ दस्तावेज़ और सेटिंग्स \ \ प्रशासक \ \ डेस्कटॉप \ \ SigmaS1.csv'
तालिका में `mydb` MyTable `
मैदान '\ \' द्वारा बच
द्वारा समाप्त ','
वैकल्पिक रूप से घिरा '"'
'\ R \ n' द्वारा समाप्त लाइनों
(`उपयोगकर्ता,` लोक निर्माण विभाग `,` sno `,` AMT `,` ActiveRec `);
csv फ़ाइल से एक अतिरिक्त लाइन स्क्रिप्ट पढ़ रही है. जैसे अगर csv फ़ाइलें 25 रिकॉर्ड है इससे पता चलता है कि वहाँ 26 रिकॉर्ड कर रहे हैं. आप कर सकते हैं कृपया मुझे बताओ मैं कहाँ गलत जा रहा हूँ?
मैं अगर यह एक पहली पंक्ति है की जाँच करें और अपनी पहली पंक्ति अगर पाश को जारी रखने के लिए जोड़ा है.
धन्यवाद
गैरी की तरह, मैं एक मौजूदा रिकॉर्ड को अधिलेखित करने में सक्षम हो चाहते हैं, लेकिन यह अद्यतन, हटाने DB में सभी डेटा नहीं. यहीं कहीं सपा:
अगर ($ addauto)
$ क्वेरी = $ databasetable मूल्यों में डालने (",'$ linemysql');";
अन्य
$ क्वेरी = $ databasetable मूल्यों ('linemysql डॉलर में डालने');";
मैं देखने के लिए अगर रिकॉर्ड मौजूद कैसे की जाँच करें और तब सम्मिलित बजाय अद्यतन?
मैं पहली लाइन / पंक्ति है जो csv फ़ाइल में कोई शीर्ष लेख कैसे छोड़ कर और डीबी में डेटा के बाकी सम्मिलित कर सकते हैं?
@ गैरी
आप एक @ mysql_query ("databasetable $ truncate") का उपयोग सकता है, सही @ mysql_select_db बयान के बाद.
लेकिन सावधान रहना इस कार्रवाई के रूप में डेटा पोंछ और पलटवाँ नहीं है.
@ कीश
वर्तमान कोड / फ़ाइल को अपलोड करने के लिए ब्राउज़िंग अनुमति नहीं है.
आप बस PHP स्क्रिप्ट के रूप में एक ही निर्देशिका में CSV फ़ाइल में डाल सकते हैं, और बस csvfile $ चर सेट करने के लिए फ़ाइल नाम के बराबर हो (पथ के बिना)
हाय सब,
कैसे मैं तारीख में इन csv उद्धरण अपने डेटा बेस में एक स्तंभ के लिए "दिन, महीने की तारीख, 2010" और राज्य "prov, राज्य" हो? मैं कई उदाहरण देख सकते हैं लेकिन मैं यह काम करने के लिए नहीं मिल सकता है. कोई मदद अच्छा होगा.
एके, 10037591,1, "मंगलवार, मार्च 9, 2010 15:55:16", 59.7151, -151.4434,2.7,75.90,32 "Kenai प्रायद्वीप, अलास्का"
thx
Pingback: data_type
धन्यवाद, इस कोड को वास्तव में मदद की है!
मैं इसे कैसे संशोधित करने के लिए किसी प्रपत्र में जो उपयोगकर्ता browses और csv फ़ाइल का चयन तालिका में आयात किया जा प्रदर्शित करने के लिए अनुमति होगी?
और भी मैं यह इतना है कि हर बार एक नई फ़ाइल प्रस्तुत है यह ओवरराइड जो कुछ वर्तमान तालिका में संग्रहीत किया जाता है कैसे कर सकता है?
बहुत धन्यवाद
यह मेरे लिए बहुत उपयोगी कोड है ..
धन्यवाद.
कैसे मैं ब्राउज़ फ़ाइल पूर्ण पथ नाम लिखने के बजाय मिल सकती है ..
कृपया इस में मदद करें.
धन्यवाद
मैं यह नहीं मिलता कि यह कैसे एक फ़ाइल नियंत्रण से काम किया. मतलब पहले ब्राउज़ करें और एक फ़ाइल का चयन और फिर सबमिट मैं कहाँ करने के लिए संशोधित की आवश्यकता
नमस्कार,
कुछ संशोधनों बनाया गया था. "|" वर्ण (पाइप) मेरा txt फ़ाइल के तीन स्तंभों द्वारा अलग है. स्क्रिप्ट फ़ाइल डेटा को प्रदर्शित करता है, पंक्तियाँ मायने रखता है, लेकिन डेटाबेस में प्रवेश नहीं करता है डेटा. कोई टिप्पणी?
$ Csvcontent = fread ($ फ़ाइल, $ आकार);
fclose ($ फ़ाइल);
$ चुनाव = @ ($ dbhost, $ dbusername, $ dbuserpassword) mysql_connect या मर ((mysql_error));
@ ($ डेटा स्रोत) mysql_select_db या मर ((mysql_error));
$ Lineseparator = "\ n";
$ Fieldseparator = "|";
$ = 0 लाइनों;
$ प्रश्नों = "";
$ Linearray = सरणी ();
$ = 0 गिनती;
foreach (विभाजन ($ lineseparator, $ csvcontent) के रूप में $ पंक्ति) {
$ गिनती = $ गिनती + 1;
$ लाइनों + +;
$ पंक्ति = ट्रिम कर दीजिए ($ लाइन, "\ t");
$ पंक्ति = str_replace ("\ r ","",$ लाइन);
/************************************
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
************************************/
$ पंक्ति = str_replace ("'"," \ "'$) लाइन;
/*************************************/
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$ Linemysql = फटना (""",$ linearray);
अगर ($ addauto)
क्वेरी $ = संकेतक मूल्यों में डालने "('$ गिनती', '$ linemysql');";
अन्य
$ क्वेरी = डालने संकेतक मूल्यों ('$ linemysql में');";
$ .= क्वेरीज़ $ क्वेरी. "\ N";
@ ($ क्वेरी) mysql_query या मरने ((mysql_error));
गूंज "$" \ linemysql n ";
}
बहुत बढ़िया स्क्रिप्ट! मैं एक परियोजना पर मैं काम कर रहा था के लिए एक छोटे से कूदना शुरू की जरूरत है और इस चाल किया.
I did notice something odd however, I modified the script to work with a form and I did notice that for searching, the last field was getting buggered up because the new line char (either \r or \n or both) was still being recorded in the MySQL database.
To that end, if you replace:
$line = str_replace(“\r”,”",$line);
with:
$line = str_replace('\r',”,$line);
it will keep the return from being a problem, as for the new line, I have added a little something that allows for inserting new records, but updates existing records, so that you don't end up with duplicate entries. At the top of the code below, you will see where I made the same fix for the actual new line char.
$linemysql = implode(“','”,$linearray);
$newlinemysql = str_replace('\n',”,$linemysql);
if($addauto) {
switch($databasetable) {
case('address'):
$duplicatevals = “address = VALUES(address),
city = VALUES(city),state = VALUES(state),
zip = VALUES(zip)”;
break;
case('owner'):
$duplicatevals = “ownername = VALUES(ownername),
housetype = VALUES(housetype),
addresskey = VALUES(addresskey)”;
break;
}
$query = “insert into $databasetable values(”,'$newlinemysql')
ON DUPLICATE KEY UPDATE
$duplicatevals”;
} else {
$query = “insert into $databasetable values('$linemysql')
ON DUPLICATE KEY UPDATE
$duplicatevals”;
}
Also, in my form I added the table name and whether I wanted the table to be [boolean] “addauto” or not as a single input from a drop-down (comma separated), then split the result at the top of the simplecsvimport 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!
चीयर्स!
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 -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. नीचे देखें.
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.
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?
नमस्कार,
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.
सादर
Adrian
सभी को हाय!
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)
धन्यवाद
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
लोड डेटा तालिका टेबल क्षेत्रों में स्थानीय पथ 'infile', '' \ 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
धन्यवाद
stan
With regards to the quotes issue, you can just use this:
$linearray = preg_split(“/,(?=(?:[^\"]*\”[^\"]*\”)*(?![^\"]*\”))/”, $line);
चीयर्स,
Gaz.
Dear Chris,
please replace:
@ Mysql_query ($ क्वेरी);
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…
किसी भी विचार?
धन्यवाद
सी
हाय मार्क,
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.
हाय सब,
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? अग्रिम धन्यवाद.
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
insert into production
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
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
insert into production
insert into production
insert into production
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
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. Any thoughts?
it did not insert into the database table where i want it inserted..:(
Nice work chief
हाय सब,
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) {
$ लाइनों + +;
$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;
}
/************************************
यह पंक्ति विशेष वर्ण पलायन. इसे हटाने अगर प्रविष्टियों csv फ़ाइल में पहले से ही बच रहे हैं
************************************/
$line = str_replace(“'”,”\'”,$line);
/*************************************/
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$linemysql = implode(“','”,$linearray);
if($addauto)
$query = “insert into $databasetable ($columnsql) values('$linemysql');”;
else
$query = “insert into $databasetable ($columnsql) values('$linemysql');”;
$queries .= $query . “\n”;
@ Mysql_query ($ क्वेरी);
}
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
else
$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, लाइन डॉलर) में विस्फोट;
… 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
Pingback: » CSV import
Pingback: Import a Comma Delimited File Into MySql with a PHP Script | eCommerce & SEO
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());
$ = 0 लाइनों;
$ प्रश्नों = "";
$linearray = array();
$count = 0;
foreach(split($lineseparator,$csvcontent) as $line) {
$count = $count + 1;
$ लाइनों + +;
$line = trim($line,”\t”);
$line = str_replace(“'”,”\'”,$line);
$ Linearray = ($ fieldseparator, लाइन डॉलर) में विस्फोट;
$linemysql = implode(“','”,$linearray);
$query = “insert into `your db table` VALUES('$count','$linemysql');”;
$queries .= $query . “\n”;
@ Mysql_query ($ क्वेरी);
}
//@mysql_close($con);
Pingback: » Converting csv to sql using php @The Coding Pad: Programming blog, discussions, tutorials, resources
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.