Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   query to upload csv file to table error (http://www.go4expert.com/forums/query-upload-csv-file-table-error-t1184/)

daiondoroga 13Aug2006 01:20

query to upload csv file to table error
 
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 13Aug2006 10:07

Re: query to upload csv file to table error
 
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);
}



All times are GMT +5.5. The time now is 00:35.