Use caution if you are not handling things like NULL, character sets, etc.
The first alternative:
<?php
$pdo = new PDO(...);
$results = $pdo->query("SELECT * FROM myTable INTO OUTFILE 'data.txt'");
$dummy = $result->fetchAll();
The data.txt file will be written to the MySQL server. The directory must be writable via the uid of the mysqld process. It will not overwrite any existing file and requires that you have FILESQL privilege .
Second alternative: use mysqldump to output to a text file (as @OMG Ponies mentioned):
mysqldump -t -T <directory> <database> <table>
It works like INTO OUTFILEit needs to be run on the MySQL server host, and the directory must be writable using mysqld uid.
Third option: run a query with the mysql client and print the text:
mysql -B -e "SELECT * FROM MyTable" <database> > mytable.txt
. NULL , mysqldump INTO OUTFILE.