0

I'm working on a small project in php to import a csv files into a MySQL table. I'm currently just using a small test table and csv however I keep getting an error thrown at me and I cant seem to spot it. I've looked at other peoples solutions and while there are differences I haven't found anything that should be stopping the import.

query is as follows:

LOAD DATA LOCAL INFILE '".$this->upload_name."' 
IGNORE INTO TABLE `testings` 
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY '\\' 
LINES TERMINATED BY '\\n'

cvs is as follows

bob,builder,10,a
john,smith,5,a
happy,camper,8,a
johhny,ball,12,a

Table is as follows

fname  varchar(100)
sname  varchar(100)
copies  int(8)      
nowt  varchar(100) 

Error is as follows

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 '\n'' at line 6

Any help would be greatly appreciated as I'm racking my head here trying to see the problem.

4

1 回答 1

0

表名不能用引号引起来。如果它不是 MySQL 保留关键字,则一般使用反引号或不使用任何反引号。

"LOAD DATA 
LOCAL INFILE " . $this->upload_name . "
IGNORE INTO TABLE `testings`
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY '\\' 
LINES TERMINATED BY '\\n'"
于 2013-05-23T12:10:33.310 回答