Jump to content

[SOLVED] LOAD DATA INFILE syntax error


salami1_1

Recommended Posts

Hi,

 

I've been searching for examples and read the Mysql docs but I just can't see the error:

My code:

$sql = "LOAD DATA INFILE '$tmpfile_lng1_name' REPLACE INTO TABLE $table1 (id, content, lastupdated) FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\n'";

 

The file has 1 line atm to test which is:

"216";"SRS <span class=blue>forbidden</span>";"2009-01-22 01:01:53";

 

The file was originally \t delimited and tried that too but same error always.

 

The 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 'FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY ' '' at line 1

 

The query echo'd with the error gives:

LOAD DATA INFILE 'credit/en.txt' REPLACE INTO TABLE ics_lng_en (id, content, lastupdated) FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY ' '

 

as you see the prob is not with the variables the \  and the \n in the query are gone because its echo'd and browser sees them as code.

 

Can anybody help me? Thanks, I've been staring at this for the last 2 days.

 

Best regards,

 

P.s. I also tried LOAD DATA LOCAL INFILE; same error, also tried removing the field ( '(id, content, lastupdated)' )

Link to comment
Share on other sites

If MySQL says error is 'near FIELDS TERMINATED BY... ' it usually means, there's something wrong just BEFORE 'FIELDS TERMINATED BY'

 

MySQL manual doesn't list 'REPLACE' as a viable part of 'LOAD DATA INFILE' statement... where did you get it?

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

 

[edit]

Got my glasses on

Link to comment
Share on other sites

yeah I know how that error reporting works.. but I just don't see the error..

 

aaah I found a way that it works:

$sql = "LOAD DATA INFILE '".$tmpfile_lng1_name."' REPLACE INTO TABLE ".$table1." FIELDS TERMINATED BY ';' ENCLOSED BY '\"'  LINES TERMINATED BY '\n'";

 

I tried before without specifying the table columns but then I had ENCLOSED BY '\"' before the word FIELDS which is bad.

Now I'm getting access denied error but on my quest of searching for this answer I saw that error passing by multiple times to I'll bet I can find some answer for that using my friend google.

 

thanks

 

Link to comment
Share on other sites

and then I find out that my hosting (Bluehost) doesn't even support this mysql functionality despite the fact they actually pointing me out to an article in THEIR helpdesk database which tells you using LOAD DATA INFILE is very good and fast blablabla

 

ergo, waste of time. humppff time for some dedicated hosting

 

b.r.

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.