I have a mysql database running in Amazon RDS, and I want to know how to export an entire table to csv format. I currently use mysql server on Windows to query the Amazon da
I'm using Yii Framework on EC2 connecting to RDS mySQL. The key is to use fputcsv(). The following works perfectly, both on my localhost as well as production.
$file = 'path/to/filename.csv';
$export_csv = "SELECT * FROM table";
$qry = Yii::app()->db->createCommand($export_csv)->queryAll();
$fh = fopen($file, "w+");
foreach ($qry as $row) {
fputcsv($fh, $row, ',' , '"');
}
fclose ($fh);