i want to import csv file to mysql database. the upload was success. but nothing to import. I think i’m wrong in sql query. here is my query :
mysql_query("LOAD DATA LOCAL INFILE '$filename' INTO TABLE CityBlocks FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n' IGNORE 2 LINES (startIpNum, endIpNum, locId)") or die (mysql_error());
and the error is :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” IGNORE 2 LINES (startIpNum, endIpNum, locId)’ at line 2
Can you tell me where is my mistake and how to fix this problem. Thank You.
You seem to have an extra ” here:
ENCLOSED BY ‘\”‘
Sorry my bad, they are enclosed by ” so it is correct to escape with \.
LINES TERMINATED BY ‘\r\n’
Have you tried modify this line to use only ‘\n’:
LINES TERMINATED BY ‘\n’
Also try not using the LOCAL keyword