soft genic
soft genic

Reputation: 2056

Problems in creating output file of my query result

Following is my sql query which worked fine when i ran it from phpmyadmin but when i ran the same query through PHP then the query didnot worked and gave me following error. Kindly let me know how can I run this query from my php file so it will create the output file in the specified folder. Thanks,

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

ERROR: File 'b:uploadeddata.csv' already exists

NOTE: The uploaded folder was empty

Upvotes: 2

Views: 122

Answers (1)

Mike Brant
Mike Brant

Reputation: 71422

It looks you are trying to run this on a windows system, which requires special treatment of directory separators.

Try:

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

Or:

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

Also note that this will not overwrite an existing file (which is the error you are getting). So you need to make sure that any file with that name is deleted first.

See the The “\” path name separator character section on this page in the MYSQL docs: http://dev.mysql.com/doc/refman/5.0/en/limits-windows.html

Upvotes: 2

Related Questions