Reputation: 730
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 TABLE
students` FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ESCAP' at line 1
Upvotes: 0
Views: 116
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