query to upload csv file to table error

daiondoroga's Avatar
Go4Expert Member
I am using a webpage that simply runs this query (so client can use it).
It is supposed to empty the table (the theory being that it resets the auto-incrementing ID to 1 again - which it doesn't!).

Then it should take the file off the clients desktop, upload it to the server and put it into the table. There's something wrong with the syntax of the second query yet it is EXACTLY the same, apart from the file location, as what DOES work when you use phpmyadmin.

Tired......look forward to your help. Thanks. Incidentally probably don't need the TRUNCATE query if I use REPLACED in the second one.

Error given is ....unexpected T_CONSTANT_ENCAPSED_STRING

{
// Run query
mysql_query("TRUNCATE TABLE `books`", $eg_objConn1);
mysql_query("LOAD DATA LOCAL INFILE 'C:/Documents and Settings/Jon/Desktop/anita.csv' REPLACE INTO TABLE 'books' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n' IGNORE 1 lines", $eg_objConn1);
}
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Hi,
You didn't escape the double quotes inside the string, ENCLOSED BY '"'
Here is the correct query.

Code: PHP
{
// Run query
mysql_query("TRUNCATE TABLE `books`", $eg_objConn1);
mysql_query("LOAD DATA LOCAL INFILE 'C:/Documents and Settings/Jon/Desktop/anita.csv' REPLACE INTO TABLE 'books' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n' IGNORE 1 lines", $eg_objConn1);
}