Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: Help importing CSV file into MySql

Started 1 month, 4 weeks ago by franwpd
I am trying to import a csv file, comma delimited, into MySql database. This is my script: $fcontents = file ('./importfile.csv'); for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(",", $line); $sql = "insert into books values ('". implode("','", $arr) ."')"; mysql_query($sql);...
Site: PHPBuilder.com  PHPBuilder.com - site profile
Forum: General Help  General Help - forum profile
Total authors: 2 authors
Total thread posts: 2 posts
Thread activity: no new posts during last week
Domain info for: phpbuilder.com

Other posts in this thread:

Kudose replied 1 month, 4 weeks ago
That error indicates that the number of columns you are inserting into does not match the number of values you are inserting. You should use mysql_real_escape_string to handle the quotes for each value, or an adapter that has prepared statements, such as PDO. You should also look into MySQL's LOAD DATA ... http://dev.mysql.com/doc/refman/5.1/en/load-data.h tml

 

Top contributing authors

Name
Posts
Kudose
2
user's latest post:
Help importing CSV file into MySql
Published (2009-11-09 00:50:00)
That error indicates that the number of columns you are inserting into does not match the number of values you are inserting. You should use mysql_real_escape_string to handle the quotes for each value, or an adapter that has prepared statements, such as PDO. You should also look into MySQL's LOAD DATA ... http://dev.mysql.com/doc/refman/5.1/en/load-data.html
franwpd
1
user's latest post:
Help importing CSV file into MySql
Published (2009-11-08 23:34:00)
I am trying to import a csv file, comma delimited, into MySql database. This is my script: $fcontents = file ('./importfile.csv'); for($i=0; $i&lt;sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(&quot;,&quot;, $line); $sql = &quot;insert into books values ('&quot;. implode(&quot;','&quot;, $arr) .&quot;')&quot;; mysql_query($sql); echo $sql...

Related threads on "PHPBuilder.com":

Related threads on other sites:

Thread profile page for "Help importing CSV file into MySql" on http://www.phpbuilder.com. This report page is a snippet summary view from a single thread "Help importing CSV file into MySql", located on the Message Board at http://www.phpbuilder.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity