Page 1 of 1

Export query results to file

Posted: Wed Nov 05, 2003 1:46 pm
by Unipus
Hi. I need to send the results of a query to someone who does not have access to our database. This result set is 2500+ items long, which exceeds the buffer of my client, so copy & paste won't work. I know i can dump the table itself to a file, but I really need the sorted results of the rather elaborate query. I'm stumped.

Posted: Wed Nov 05, 2003 1:57 pm
by JAM

Code: Select all

select into outfile 'filename' їexport options] from table where foo = bar
[mysql_man]SELECT[/mysql_man] for more info (very end of the main page)

Posted: Thu Nov 06, 2003 12:35 am
by BDKR
If you want to do some formatting of that data in a special way, you could just write out to a file handle using something like fopen() and fwrite(). Another option would be to just echo the formatted data and pipe it into a document. At the command line it would look something like...

Code: Select all

your_script.php > output.txt
This is command line stuff FYI. The above line will work in both Windows and Linux.

Cheers,
BDKR