satre Posted March 5, 2010 Share Posted March 5, 2010 Hi, This is driving me nuts: $sql = "LOAD DATA LOCAL INFILE 'MR@20Stroke-Trauma@2010.07.txt' 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 Quote Link to comment 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`. Quote Link to comment 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@20Stroke-Trauma@2010.07.txt' INTO TABLE `test` FIELDS TERMINATED BY ' ' ENCLOSED BY '\"' (`type` , `command` , `value`)"; Quote Link to comment 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.