Export query results to file

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
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Export query results to file

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
Post Reply