Page 1 of 1

MySQL - SELECT ... INTO OUTFILE

Posted: Wed Jul 16, 2008 4:25 am
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

Re: MySQL - SELECT ... INTO OUTFILE

Posted: Wed Jul 16, 2008 2:50 pm
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.

Re: MySQL - SELECT ... INTO OUTFILE

Posted: Sat Jul 19, 2008 11:33 am
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