satre Posted March 5, 2010 Share Posted March 5, 2010 Hi, This is driving me nuts: $sql = "LOAD DATA LOCAL INFILE 'MR@[email protected]' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\\n'(`type` , `command` , `value`)"; $loaddata = mysql_query($sql); if (!$loaddata) { die('Could not load data into table: ' .mysql_error()); } Gives me an error: 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 '\n'(`type` , `command` , `value`)' at line 1 I've tried all the obvious things I can think of. If I take out the \ in front of \n, I still get an error but it' doesn't include the \n. I tried doing \\r\\n, still have the context error. Anybody have an idea? Can LOAD DATA LOCAL INFILE be used in php? The (unescaped) command works fine when I'm in my phpMyAdmin SQL terminal. Thanks!! Satre Link to comment https://forums.phpfreaks.com/topic/194279-load-data-local-infile-using-php-context-error/ Share on other sites More sharing options...
cags Posted March 5, 2010 Share Posted March 5, 2010 The only thing I can thing of is perhaps you need a space between '\\n' and (`type`. Link to comment https://forums.phpfreaks.com/topic/194279-load-data-local-infile-using-php-context-error/#findComment-1022161 Share on other sites More sharing options...
satre Posted March 8, 2010 Author Share Posted March 8, 2010 Nothing seemed to work on this. I think the answer may be lying in the construction of the .txt file data itself. I removed the escape and termination parameters and then everything worked. Always getting a MySQL syntax error if I left those parameters in. Here's what worked: $sql = "LOAD DATA LOCAL INFILE 'MR@[email protected]' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' (`type` , `command` , `value`)"; Link to comment https://forums.phpfreaks.com/topic/194279-load-data-local-infile-using-php-context-error/#findComment-1023116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.