note 59774 added to function.mysql-list-tables
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 15 Dec 2005 14:38:42 +0000 |
| Subject: | note 59774 added to function.mysql-list-tables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100193@lists.php.net to get a copy of this message | ||
Getting the database status:
<?
// Get database status by DtTvB
// Connect first
mysql_connect ('*********', '*********', '********');
mysql_select_db ('*********');
// Get the list of tables
$sql = 'SHOW TABLES FROM *********';
if (!$result = mysql_query($sql)) { die ('Error getting table list (' . $sql . ' ::
' . mysql_error() . ')'); }
// Make the list of tables an array
$tablerow = array();
while ($row = mysql_fetch_array($result)) { $tablerow[] = $row; }
// Define variables...
$total_tables = count($tablerow);
$statrow = array();
$total_rows = 0;
$total_rows_average = 0;
$sizeo = 0;
// Get the status of each table
for ($i = 0; $i < count($tablerow); $i++) {
// Query the status...
$sql = "SHOW TABLE STATUS LIKE '{$tablerow[$i][0]}';";
if (!$result = mysql_query($sql)) { die ('Error getting table status (' . $sql . '
:: ' . mysql_error() . ')'); }
// Get the status array of this table
$table_info = mysql_fetch_array($result);
// Add them to the total results
$total_rows += $table_info[3];
$total_rows_average += $table_info[4];
$sizeo += $table_info[5];
}
// Function to calculate size of the file
function c2s($bs) {
if ($bs < 964) { return round($bs) . " Bytes"; }
else if ($bs < 1000000) { return round($bs/1024,2) . " KB" ; }
else { return round($bs/1048576,2) . " MB" ; }
}
// Echo the result!!!!!!!!!
echo "{$total_rows} rows in {$total_tables} tables";
echo "<br>Average size in each row: " . c2s($total_rows_average/$total_tables);
echo "<br>Average size in each table: " . c2s($sizeo/$total_tables);
echo "<br>Database size: " . c2s($sizeo);
// Close the connection
mysql_close();
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-list-tables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59774
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59774&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59774&report=yes
Search -- http://master.php.net/manage/user-notes.php