Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Created July 29, 2020 14:52
Show Gist options
  • Save iggyvolz/933f6f1f658460e52f2dea82905263be to your computer and use it in GitHub Desktop.
Save iggyvolz/933f6f1f658460e52f2dea82905263be to your computer and use it in GitHub Desktop.
<?php
use GCCISWebProjects\Utilities\DatabaseTable\PDOMysqlDriver;
use GCCISWebProjects\Utilities\DatabaseTable\Condition\AlwaysTrueCondition;
require_once __DIR__ . "/../../vendor/autoload.php";
$db = new PDOMysqlDriver("/tmp/mysql.sock");
$db->query("USE gwp;");
foreach(array_map(fn(array $x):string => $x[0], iterator_to_array($db->query("SHOW TABLES"))) as $table) {
$data = (iterator_to_array($db->query("SELECT * FROM `$table`")));
// Take out integer keys
$data = array_map(fn(array $row):array => array_filter($row, "is_string", ARRAY_FILTER_USE_KEY), $data);
if($data) {
$file = fopen(__DIR__ . "/../../_starterData/$table.csv", "w");
fputcsv($file, array_keys($data[0]));
foreach($data as $row) {
fputcsv($file, array_map(fn($s):string => is_null($s) ? "\\N" : strval($s), array_values($row)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment