superfriend Posted August 17, 2010 Share Posted August 17, 2010 Hi. I am running WOS portable as my server. The following script runs in phpAdmin in the SQL window. But when placed in a .php file and the php file is run, it complains. $sql = "LOAD DATA LOCAL INFILE 'E:\\php\\www\\folder\\file.csv' INTO TABLE test_csv FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n' IGNORE 1 LINES "; $result = mysql_query($sql) or die(mysql_error()); Will be back to add error message. Quote Link to comment https://forums.phpfreaks.com/topic/211012-load-data/ Share on other sites More sharing options...
superfriend Posted August 17, 2010 Author Share Posted August 17, 2010 Error Message: 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 1 LINES' at line 6 I spent hours today looking at this, reviewing a number of sites. One idea I think the problem might be is the double quote delimiter. ENCLOSED BY '\"' is single quote backslash double quote single quote without the backslash, the double quote ends the string. Suggestions please. Erik. Quote Link to comment https://forums.phpfreaks.com/topic/211012-load-data/#findComment-1100540 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 What happens if you echo the query to the screen, then copy/paste it into phpMyAdmin? Quote Link to comment https://forums.phpfreaks.com/topic/211012-load-data/#findComment-1100551 Share on other sites More sharing options...
superfriend Posted August 18, 2010 Author Share Posted August 18, 2010 Thank you for that suggestion. Echoing caused it to fail in phpAdmin. I was able to see what SQL thought the query was. I had unintentionally escaped a single quote, leaving an unfinished string. That led to realizing I needed a lot more escape characters. The final result is this: <?php $sql = "LOAD DATA LOCAL INFILE 'E:\\\\php\\\\www\\\\folder\\\\file.csv' " ."INTO TABLE test_csv " ."FIELDS TERMINATED BY ',' " ."ENCLOSED BY '\"' " ."ESCAPED BY '\\\\' " ."LINES TERMINATED BY '\\r\\n' " ."IGNORE 1 LINES "; echo $sql; ?> Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/211012-load-data/#findComment-1100800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.