Ds.109
Ds.109

Reputation: 730

LOAD FILE MySQL & PHP

Trying to load a CSV into a MySQL database. Can't get it to work...

SQL Query =

$query = "LOAD DATA LOCAL INFILE `$ptempName` INTO TABLE `students` FIELDS TERMINATED BY ','  LINES TERMINATED BY '\r' ESCAPED BY ',' ENCLOSED BY '" . '"' . "   ('StudentNumber', 'FirstName', 'LastName' , 'Gender' , 'Year', 'Email', 'DOB', 'Phone', 'Notifications');";
$result = mysql_query($query)or die ('Error: '.mysql_error ());

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 '` INTO TABLEstudents` FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ESCAP' at line 1

Upvotes: 0

Views: 116

Answers (1)

tadman
tadman

Reputation: 211540

Backticks are used to escape database, table and column names only.

For strings you can usually use single or double quotes, as in '$ptempName'.

Be absolutely sure you have properly escaped this value if you are getting it from a user. When using mysql_query you are playing with fire.

Upvotes: 2

Related Questions