我尝试使用在线发现的PHP脚本没有成功,所以我恢复使用mySQL语法OUTFILE,这是我尝试使用的当前代码,虽然它会抛出一些错误
SELECT Name, ID INTO OUTFILE 'data.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM data
如下所示抛出错误
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
答案 0 :(得分:2)
看起来这个错误是由PHP抛出的。尝试转义双引号
SELECT Name, ID INTO OUTFILE 'data.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM data
如果以上查询有效,请尝试再次转义反斜杠。
SELECT Name, ID INTO OUTFILE 'data.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY '\\\\'
LINES TERMINATED BY '\n'
FROM data