#!/usr/bin/php query(" SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name "); while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $tables[] = $row['name']; } if (empty($tables)) { echo "No tables found.\n"; exit(0); } echo "Tables found:\n"; foreach ($tables as $table) { echo " - $table\n"; } echo "\n"; /** * Dump contents of each table */ foreach ($tables as $table) { echo "=============================\n"; echo "TABLE: $table\n"; echo "=============================\n"; $res = $db->query("SELECT * FROM \"$table\""); // Fetch column names $columns = []; for ($i = 0; $i < $res->numColumns(); $i++) { $columns[] = $res->columnName($i); } echo implode("\t", $columns) . "\n"; echo str_repeat('-', 80) . "\n"; $rowCount = 0; while ($row = $res->fetchArray(SQLITE3_ASSOC)) { echo implode("\t", array_map( fn($v) => $v === null ? 'NULL' : (string)$v, $row )) . "\n"; $rowCount++; } if ($rowCount === 0) { echo "(no rows)\n"; } echo "\n"; } $db->close();