0

我正在尝试使用 PHP 脚本在数据库中上传 CSV 文件。我正在写的查询是

mysql_query("LOAD DATA LOCAL INFILE  'data.csv' INTO TABLE  `raw_data` FIELDS TERMINATED BY  ',' ENCLOSED BY  '"' ESCAPED BY  '\\' LINES TERMINATED BY '\n' ");

我在运行此脚本时遇到的错误是

Parse error: parse error in C:\wamp\www\price\godata.php on line 5

任何人都可以告诉我我在哪里做错了吗?

4

2 回答 2

1

从外观上看,您在以双引号"终止的字符串中使用了双引号。您将需要转义字符,您可以这样做:

mysql_query("LOAD DATA LOCAL INFILE  'data.csv' INTO TABLE  `raw_data` 
             FIELDS TERMINATED BY  ',' ENCLOSED BY  '\"' ESCAPED BY  '\\' 
             LINES TERMINATED BY '\n' ");         // ^ PHP Thought your command 
                                                  // ended at that point
于 2013-09-07T23:35:28.597 回答
-1

将转义\字符放在"ie 之前将ENCLOSED BY '"'替换为ENCLOSED BY '\"'

于 2013-09-07T23:36:19.687 回答