Skip to content

Instantly share code, notes, and snippets.

@notmike101
Last active August 29, 2015 14:03
Show Gist options
  • Save notmike101/46c983d708b719b63530 to your computer and use it in GitHub Desktop.
Save notmike101/46c983d708b719b63530 to your computer and use it in GitHub Desktop.
<?php
// Using mysql for backwards compatibility.
// Disable that pesky depreciated warning with php5.
error_reporting(E_ALL ^ E_DEPRECATED);
// We need to have our database information somewhere.
$conf = Array(
'host' => '127.0.0.1', // Host
'user' => 'root', // Username
'pass' => '', // Password
);
// An array to hold the database information
$databases = Array();
// Connect to the database
$db = mysql_connect($conf['host'], $conf['user'], $conf['pass']);
// Get a list of all the databases we have access to
$res = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_assoc($res)) {
// Get rid of the useless information
if(!in_array($row['Database'],Array('information_schema','mysql','performance_schema','phpmyadmin'))) {
// Add the database to our array
$databases[$row['Database']] = Array();
// Get a list of all the table names we have access to
$res2 = mysql_query("SHOW TABLES FROM ".$row['Database']);
while ($row2 = mysql_fetch_array($res2)) {
// Add the table names to our array under the correct database
$databases[$row['Database']][$row2[0]] = Array();
// Get list of all the column names we have access to
$res3 = mysql_query("SHOW COLUMNS FROM `".$row['Database']."`.`".$row2[0]."`");
while ($row3 = mysql_fetch_array($res3)) {
// Get all information from that column
$res4 = mysql_query("SELECT * FROM `".$row['Database']."`.`".$row2[0]."`");
while ($row4 = mysql_fetch_array($res4)) {
// Store the information in the correct table/column within the array
$databases[$row['Database']][$row2[0]][$row3['Field']] = $row4[$row3['Field']];
}
}
}
}
}
// House keeping
mysql_free_result($res4);
mysql_free_result($res3);
mysql_free_result($res2);
mysql_free_result($res);
mysql_close();
// And display!
echo "<pre>";
print_r($databases);
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment