Created
March 24, 2016 07:15
-
-
Save dapepe/e9d0ec33037b3f8e0532 to your computer and use it in GitHub Desktop.
Display a dump for an SQLite file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
if ( !isset($argv[1]) ) { | |
fputs(STDERR, 'Usage: '.basename($argv[0]).' <sqlite-file>'."\n"); | |
exit(1); | |
} | |
$dbFile = $argv[1]; | |
$con = new PDO('sqlite:'.$dbFile); | |
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$statement = $con->query('SELECT * FROM SQLITE_MASTER'); | |
$rows = $statement->fetchAll(PDO::FETCH_ASSOC); | |
$statement->closeCursor(); | |
$statement = null; | |
foreach ($rows as $row) { | |
if ( !isset($row['type'], $row['name'], $row['sql']) or | |
($row['type'] !== 'table') ) | |
continue; | |
echo $row['sql'].";\n\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment