将MySQL下载为CSV的问题

时间:2011-03-29 19:38:02

标签: php mysql csv download

我无法将mysql数据库输出到csv文件并下载它。波纹管代码在下面的第3行产生错误"unexpected T_CONSTANT_ENCAPSED_STRING"。我用分号尝试了它,没有在第3和第4行。

$FileName = "/googleresearch" .  abs(rand(0,1000000000000))  .  ".csv";

$query = "SELECT * FROM happyturtle INTO OUTFILE $FileName;
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';
LINES TERMINATED BY '\n'";

$result = mysql_query($query) or die(mysql_error());

exit;

1 个答案:

答案 0 :(得分:4)

您需要在第四行逃离",如:

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"';