创建查询结果的输出文件时出现问题

时间:2012-12-26 16:41:08

标签: php mysql

以下是我的SQL查询,当我从phpmyadmin运行它时工作正常,但当我通过PHP运行相同的查询时,查询没有工作,并给了我跟随错误。请告诉我如何从我的php文件运行此查询,以便它将在指定的文件夹中创建输出文件。谢谢,

QUERY

SELECT * FROM lahore_student INTO OUTFILE 'b://uploaded//data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '".'"'."'
LINES TERMINATED BY '\n'

Output: It creates file to my b drive in FOLDER named as Uploaded

错误: 文件'b:uploadeddata.csv'已存在

NOTE: The uploaded folder was empty

1 个答案:

答案 0 :(得分:2)

看起来你试图在Windows系统上运行它,这需要对目录分隔符进行特殊处理。

尝试:

SELECT * FROM lahore_student INTO OUTFILE 'b:\\uploaded\\data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '".'"'."'
LINES TERMINATED BY '\n'

或者:

SELECT * FROM lahore_student INTO OUTFILE 'b:/uploaded/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '".'"'."'
LINES TERMINATED BY '\n'

另请注意,这不会覆盖现有文件(这是您获得的错误)。因此,您需要确保首先删除具有该名称的任何文件。

请参阅MYSQL文档中此页面上的The “\” path name separator character部分: http://dev.mysql.com/doc/refman/5.0/en/limits-windows.html