0

I have tried everything that I can think of, but for some reason I cannot get this to work.

I have a piece of PHP code that loads a locally stored CSV file into a MySQL database. It works perfectly in one script:

$query = 'LOAD DATA LOCAL INFILE \''.$arp_input.'\' INTO TABLE arp_import FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'\r\n\' (not_used,account_number,check_serial,issue_date,amount,transaction_code,additional_text)';

However, I need to do the same thing (load a CSV) in another script that does essentially the same thing, but generates a different format. Here is the query:

$query = 'LOAD DATA LOCAL INFILE \''.$ap_input.'\' INTO TABLE ap_import FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'\r\n\' (account_number,check,paiddate,amount)';

But when I run the second script with the above query, I get this 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 'check,paiddate,amount)' at line 1

When I take out the field listing at the end of the second query, it only imports ONE line from the file and that is it, even when I tried the \n delimiter, \r, and both \r\n.

I have tried everything that I can think of. These two PHP scripts are running on the same server and they are both accessing the same remote MySQL server. What am I missing here?

1
  • $ap_input v.s. $arp_input (R)?. Is that intention, or is perhaps $ap_input a type and you're really trying .. INFILE '' INTO ...? Commented Apr 2, 2013 at 19:32

2 Answers 2

1

Check is a reserved word according to the MySQL documentation.

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh, so incredibly simple. That was it. Now I need to figure out why it is only taking one line..
0

check is a reserved word in MySQL ( http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html ). You should enclose it in back-ticks (`) in your sql sentence:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.