ボタンをクリックしたときにMySQLテーブルをCVSファイルにエクスポートするスクリプトをPHPで実行しました。正常に動作していますが、ボタンをクリックすると、CSVファイルごとに1つのテーブルをエクスポートする必要があります。これはすべてZIP(またはRAR)ファイルです。
基本的には次のようになります。エクスポートテーブル:
mytable.csv
すべてのテーブルをエクスポートします。
export.ZIPには以下が含まれます:
--mytable1.csv
--mytable2.csv
--mytable3.csv
各テーブルのエクスポート機能をループすることはできますが、それではすべてがZIPに入れられるわけではありません。
/* EXPORT ALL TABLES */
if (isset($_POST['export_all_tables'])){
$Qlist_table = $pdo->prepare('SHOW TABLES');
$Qlist_table->execute(array(''));
foreach ($Qlist_table as $Alist_table)
export_table($Alist_table[0]);
}
function export_table($table_to_export){
$Qselect = $pdo->prepare('SELECT * FROM '.$table_to_export.'');
$Qselect->execute(array(''));
$results = $Qselect->fetchAll(PDO::FETCH_ASSOC);
...
...
...
header("Content-disposition: attachment; filename=".$fileName);
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: application/vnd.ms-excel\n");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
echo $outputCsv;
exit();
}
エクスポート関数のすべてのコードが必要だとは思いません。はいの場合はお知らせください。
ありがとう!