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@[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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.