Welcome Guest, Not a member yet? Register   Sign In
How to import csv file to mysql
#3

[eluser]Jaketoolson[/eluser]
Why would you use a CSV parsing class and then loop through it when all he's trying to do is insert a CSV into MySQL? His SQL query was correct!

Just do what you've done in the past. What you pasted is a valid SQL query, so just execute it in your code after the file has been uploaded. In order to get the CSV file to the server, upload it using a form and then update the directory in your query. This is exactly what we do. You might need to change it to 'local'.

Code:
LOAD DATA LOCAL INFILE '/path/to/csvfile.csv' REPLACE INTO TABLE `table`
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES

The ignore 1 lines would be used if your first row contains headers.


Messages In This Thread
How to import csv file to mysql - by El Forum - 07-29-2011, 08:42 PM
How to import csv file to mysql - by El Forum - 07-30-2011, 01:27 AM
How to import csv file to mysql - by El Forum - 08-06-2011, 09:28 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 03:13 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 03:14 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 12:59 PM
How to import csv file to mysql - by El Forum - 08-08-2011, 11:54 PM
How to import csv file to mysql - by El Forum - 08-09-2011, 02:13 AM
How to import csv file to mysql - by El Forum - 08-09-2011, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB