Jump to content

LOAD DATA LOCAL INFILE using php (context error?)


satre

Recommended Posts

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

Link to comment
Share on other sites

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`)";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.