2

以下是我的 sql 查询,当我从 phpmyadmin 运行它时它运行良好,但是当我通过 PHP 运行相同的查询时,查询没有工作并给我以下错误。请让我知道如何从我的 php 文件运行此查询,以便它将在指定文件夹中创建输出文件。谢谢,

询问

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

4

1 回答 1

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'

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

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

于 2012-12-26T16:47:24.087 回答