0
 "LOAD DATA LOCAL INFILE ".$file_location." INTO TABLE p4p.users_csv_import
 FIELDS TERMINATED BY ',' 
 LINES TERMINATED BY '\\n' STARTING BY ''
 IGNORE 1 LINES";

Not sure what is incorrect, but it is with my single/double quotes.

Error Number: 1064

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 'assets/temp/p4p57.csv INTO TABLE p4p.users_csv_import FIELDS TERMINATED ' at line 1

LOAD DATA LOCAL INFILE assets/temp/p4p57.csv INTO TABLE p4p.users_csv_import FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' STARTING BY '' IGNORE 1 LINES

Filename: /Applications/MAMP/htdocs/models/user_import_model.php

Line Number: 28
5
  • 3
    What is the exact error message? What is the value of $file_location? Can you should us what the string looks like with the variable interpolated? Commented Jan 8, 2014 at 15:29
  • 2
    What error message are you getting? Commented Jan 8, 2014 at 15:30
  • '' looks like an empty string, are you sure that's what you want? Commented Jan 8, 2014 at 15:30
  • The actual error message and an echo of the actual statement submitted would both be useful. Commented Jan 8, 2014 at 15:31
  • 4
    Is $file_location quoted? Commented Jan 8, 2014 at 15:31

3 Answers 3

2

Wrap $file_location in single quotes.

Edit - specifically:

"LOAD DATA LOCAL INFILE '".$file_location."' INTO TABLE business.table
 FIELDS TERMINATED BY ',' 
 LINES TERMINATED BY '\\n' STARTING BY ''
 IGNORE 1 LINES";
Sign up to request clarification or add additional context in comments.

Comments

0

While you are not providing an error, my gut tells me the issue is with the \n which should probably be a \\n. So try this instead.

"LOAD DATA LOCAL INFILE ".$file_location." INTO TABLE business.table
 FIELDS TERMINATED BY ',' 
 LINES TERMINATED BY '\\n' STARTING BY ''
 IGNORE 1 LINES";

1 Comment

I edited to account for your correction, which was right but still missing something. I am so bad with these strings :(
0

Try with following code:

"LOAD DATA LOCAL INFILE '.$file_location.' INTO TABLE business.table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' STARTING BY '' IGNORE 1 LINES";

and share your result should it worked for you or not?

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.