Skip to content

Instantly share code, notes, and snippets.

@u-mulder
Created August 7, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u-mulder/5436cd493dc955f814c713b26f7a7de3 to your computer and use it in GitHub Desktop.
Save u-mulder/5436cd493dc955f814c713b26f7a7de3 to your computer and use it in GitHub Desktop.
Count tables in a database
<?php
try {
$dbh = new PDO('mysql:dbname=DBNAME;host=HOST', 'USER', 'PASSWORD');
} catch (\Exception $e) {
echo $e->getMessage();
die('Dead in ' . __FILE__ . ' on line ' . __LINE__ . PHP_EOL);
}
$r = $dbh->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "DBNAME"');
echo '<pre>Count: ', print_r($r->fetch()), '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment