PHP Snippets
Name:MySQL Stats
Description: Display some useful information about your MySQL, databases and tables.
Code below...
>
<?php
//Connect to database
$db = mysql_connect('localhost','user','pass') or die("Cannot connect to database");
//List all database
$dblist = mysql_list_dbs($db);
echo "<strong>MySQL databases and tables</strong>";
echo "<ul>";
for ($i = 0; $i < mysql_num_rows($dblist); $i++) {
//Store Database name
$dbl = mysql_db_name($dblist,$i);
//Display Database Name
echo "<strong><li>$dbl</li></strong>";
//Table on each database
$table = mysql_list_tables($dbl,$db);
echo "<ul>";
for ($x = 0; $x < mysql_num_rows($table); $x++) {
//Display all tables in each database
echo "<li>" . mysql_tablename($table,$x) . "</li>";
}
echo "</ul><br/>";
}
//Some MySQL Information
echo "<strong>MySQL Information</strong><br/>";
echo "Client Version:" . mysql_get_client_info() . "<br/>";
echo "Server Version:" . mysql_get_server_info() . "<br/>";
echo "Protocol Version:" . mysql_get_proto_info() . "<br/>";
echo "Host:" . mysql_get_host_info() . "<br/";
echo "Thread ID:" . mysql_thread_id() . "<br/>";
$status = mysql_stat();
echo $status;
//Close Connection
mysql_close($db);
?>
//Connect to database
$db = mysql_connect('localhost','user','pass') or die("Cannot connect to database");
//List all database
$dblist = mysql_list_dbs($db);
echo "<strong>MySQL databases and tables</strong>";
echo "<ul>";
for ($i = 0; $i < mysql_num_rows($dblist); $i++) {
//Store Database name
$dbl = mysql_db_name($dblist,$i);
//Display Database Name
echo "<strong><li>$dbl</li></strong>";
//Table on each database
$table = mysql_list_tables($dbl,$db);
echo "<ul>";
for ($x = 0; $x < mysql_num_rows($table); $x++) {
//Display all tables in each database
echo "<li>" . mysql_tablename($table,$x) . "</li>";
}
echo "</ul><br/>";
}
//Some MySQL Information
echo "<strong>MySQL Information</strong><br/>";
echo "Client Version:" . mysql_get_client_info() . "<br/>";
echo "Server Version:" . mysql_get_server_info() . "<br/>";
echo "Protocol Version:" . mysql_get_proto_info() . "<br/>";
echo "Host:" . mysql_get_host_info() . "<br/";
echo "Thread ID:" . mysql_thread_id() . "<br/>";
$status = mysql_stat();
echo $status;
//Close Connection
mysql_close($db);
?>