当我将表导出到csv时,fputcsv在带空格的值中添加双引号,例如:
day|night|summer|winter
something|123|something|"Bauer Jack"
foo|bla|5|dooper
我发现我无法避免。
当我尝试使用LOAD DATA INFILE导入此csv时,问题就变成了,它没有导入包含双引号的行。因此,“ Bauer Jack”示例行不会导入到mysql中。
$query = <<<eof
LOAD DATA LOCAL INFILE '$filename' INTO TABLE `table_name`
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
eof;
您能提出解决方案吗?为什么不导入双引号的行?
当我从csv文件中删除双引号时,一切正常。
答案 0 :(得分:0)
尝试先放置OPTIONALLY ENCLOSED BY子句。
$query = <<<eof
LOAD DATA LOCAL INFILE '$filename' INTO TABLE `table_name`
FIELDS OPTIONALLY ENCLOSED BY '"' TERMINATED BY '|'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
eof;