MYSQL Query in PHP Format

This is the SQL Query which i want to put in a variable:

LOAD DATA INFILE ‘huge.csv’
INTO TABLE country
FIELDS TERMINATED BY ’ , ’
ENCLOSED BY ’ " ’
LINES TERMINATED BY ’ \n ’
IGNORE 1 ROWS

This Works when I run it from shell. I am trying to run it from PHP but i have issues with appending the ’ " ’ part.

This is the string I am using

$sql=“LOAD DATA INFILE ‘huge.csv’ INTO TABLE huge FIELDS TERMINATED BY ‘,’ ENCLOSED BY “.’ " '.” LINES TERMINATED BY ‘\n’ IGNORE 1 ROWS”;

This is the mysql 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 ‘"LINES TERMINATED BY ’ ’ IGNORE 1 ROWS’ at line 1

What am I missing here?

just escape the doublequote: https://3v4l.org/ctk63

Thanks It Worked !

You need to be careful with that command in applications. Most MySQL server configurations don’t allow that.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.