PDA

View Full Version : CSV file



honey4u
June 11th, 2005, 08:28 AM
i was wondering if somebody could tell me that how can i upload information to my DB by using CSV file with php and mysql though i have done this with mysqlimport command but that works fine with text files so pls tell me how to do this with CSV file,
thanks

ghjr
June 11th, 2005, 09:03 PM
Don't know if MySQL has a function for importing CSV files, but you could always use phpMyAdmin or MySQL Front to do that.


Cheers!

teiz77
June 13th, 2005, 08:44 AM
A csv file is a text file. You can use mysqlimport:


mysqlimport --fields-optionally-enclosed-by=""" --fields-terminated-by=, --lines-terminated-by="\r\n" --user=YOUR_USERNAME --password YOUR_DATABASE file.csv

If you have a header in your .csv file with the name of columns or other "junk" in it, just add a --ignore-lines=X to skip the first X lines (i.e. --ignore-lines=1 to skip 1 line)

If your fields are (optionally) enclosed by double-quotes " and which themselves are doubled inside a value (i.e. a double double-quote "" = 1 double-quote ") then also use --fields-escaped-by=\ (default) and NOT --fields-escaped-by="""