MySQL - SELECT ... INTO OUTFILE

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

MySQL - SELECT ... INTO OUTFILE

Post by bouncer »

hi there.

i have a little php script that every day generates a .csv file using this mysql query,

[sql] SELECT * FROM `content` WHERE `status` < '6' AND `status` > '0' AND `date_status` BETWEEN '$startDate' AND '$endDate' INTO OUTFILE 'C:/temp/csvFiles/$csvfile'        FIELDS TERMINATED BY ';'        OPTIONALLY ENCLOSED BY ''        LINES TERMINATED BY '\n' [/sql]

everything is working good except that i have a field `info` where i can write everythink that i want related with a specific status, but if i insert a new line and then i go see the content of the csv file, i notice that it creates a new line in the file where isnt supose to be. i know that in mysql i can use FIELDS ESCAPED BY but i've already try that without sucess, maybe i'm doing something wrong. another way is to do something that i've read in the last coment in this page ( http://dev.mysql.com/doc/refman/5.0/en/select.html ).

same problem: http://lists.mysql.com/mysql/212786

i hope that you can understand what i'm saying, any help will be appreciated. :roll:

thanks in advance
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: MySQL - SELECT ... INTO OUTFILE

Post by califdon »

Is the "info" field a separate field in your `content` table? Is the problem that the "info" field may have a linefeed at the end of the string stored in the field? I can't make sense of the 2 references you gave.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: MySQL - SELECT ... INTO OUTFILE

Post by bouncer »

califdon wrote:Is the "info" field a separate field in your `content` table? Is the problem that the "info" field may have a linefeed at the end of the string stored in the field? I can't make sense of the 2 references you gave.
the info field belongs to content table, and the problem is that this field may have a line break at the end of the string, so when i look up at the file, if i have a row on the table, and if i have multiple line breaks in that field, my .csv file has mutiple lines instead of one.

i manage to solve my problem using str_replace(), but dont know if this is the best solution.

regards
Post Reply