extended to display some stats

This commit is contained in:
Loïc Chapeaux
2001-09-07 23:58:19 +00:00
parent 13880dc15c
commit 84485775aa
2 changed files with 492 additions and 52 deletions

View File

@@ -6,51 +6,216 @@
* Gets the variables sent or posted to this script, then displays headers
*/
require('./grab_globals.inc.php3');
if (!isset($message)) {
include('./header.inc.php3');
} else {
show_message($message);
}
require('./header.inc.php3');
/**
* Get the list and count of the tables
* Gets the list of the table in the current db and informations about these
* tables if possible
*/
$tables = mysql_list_tables($db);
$num_tables = @mysql_numrows($tables);
// staybyte: speedup view on locked tables - 11 June 2001
if (MYSQL_INT_VERSION >= 32303) {
// Special speedup for newer MySQL Versions (in 4.0 format changed)
if ($cfgSkipLockedTables == TRUE && MYSQL_INT_VERSION >= 32330) {
$local_query = 'SHOW OPEN TABLES FROM ' . backquote($db);
$result = mysql_query($query) or mysql_die('', $local_query);
// Blending out tables in use
if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($tmp = mysql_fetch_array($result)) {
// if in use memorize tablename
if (eregi('in_use=[1-9]+', $tmp)) {
$sot_cache[$tmp[0]] = TRUE;
}
}
mysql_free_result($result);
if (isset($sot_cache)) {
$local_query = 'SHOW TABLES FROM ' . backquote($db);
$result = mysql_query($query) or mysql_die('', $local_query);
if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($tmp = mysql_fetch_array($result)) {
if (!isset($sot_cache[$tmp[0]])) {
$local_query = 'SHOW TABLE STATUS FROM ' . backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
$sts_result = mysql_query($local_query) or mysql_die('', $local_query);
$sts_tmp = mysql_fetch_array($sts_result);
$tables[] = $sts_tmp;
} else { // table in use
$tables[] = array('Name' => $tmp[0]);
}
}
mysql_free_result($result);
$sot_ready = TRUE;
}
}
}
}
if (!isset($sot_ready)) {
$local_query = 'SHOW TABLE STATUS FROM ' . backquote($db);
$result = mysql_query($local_query) or mysql_die('', $local_query);
if ($result != FALSE && mysql_num_rows($result) > 0) {
while ($sts_tmp = mysql_fetch_array($result)) {
$tables[] = $sts_tmp;
}
mysql_free_result($result);
}
}
$num_tables = (isset($tables) ? count($tables) : 0);
} // end if (MYSQL_INT_VERSION >= 32303)
else {
$result = mysql_list_tables($db);
$num_tables = @mysql_numrows($result);
for ($i = 0; $i < $num_tables; $i++) {
$tables[] = mysql_tablename($result, $i);
}
mysql_free_result($result);
}
/**
* If there is at least one table, displays the printer friendly view, else
* an error message
*/
// No table
// 1. No table
if ($num_tables == 0) {
echo $strNoTablesFound;
}
// At least one table
else {
$i = 0;
// 2. Shows table informations on mysql >= 3.23 - staybyte - 11 June 2001
else if (MYSQL_INT_VERSION >= 32300) {
?>
<!-- The tables list -->
<table border="<?php echo($cfgBorder); ?>">
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo ucfirst($strTable); ?></th>
<th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
<th><?php echo ucfirst($strRecords); ?></th>
<th><?php echo ucfirst($strType); ?></th>
<th><?php echo ucfirst($strSize); ?></th>
</tr>
<?php
$i = $sum_entries = $sum_size = 0;
while (list($keyname, $sts_data) = each($tables)) {
$table = $sts_data['Name'];
$bgcolor = ($i++ % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo;
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td nowrap="nowrap">
&nbsp;<b><?php echo htmlspecialchars($table); ?>&nbsp;</b>&nbsp;
</td>
<?php
echo "\n";
$mergetable = FALSE;
$nonisam = FALSE;
if (isset($sts_data['Type'])) {
if ($sts_data['Type'] == 'MRG_MyISAM') {
$mergetable = TRUE;
} else if (!eregi('ISAM|HEAP', $sts_data['Type'])) {
$nonisam = TRUE;
}
}
if (isset($sts_data['Rows'])) {
if ($mergetable == FALSE) {
if ($nonisam == FALSE) {
$tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
$sum_size += $tblsize;
if ($tblsize > 0) {
list($formated_size, $unit) = format_byte_down($tblsize, 3, 1);
} else {
list($formated_size, $unit) = format_byte_down($tblsize, 3, 0);
}
} else {
$formated_size = '&nbsp;-&nbsp;';
$unit = '';
}
if (isset($sts_data['Rows'])) {
$sum_entries += $sts_data['Rows'];
}
}
// MyISAM MERGE Table
else if ($mergetable == TRUE) {
$formated_size = '&nbsp;-&nbsp;';
$unit = '';
}
else {
$formated_size = 'unknown';
$unit = '';
}
?>
<td align="right">
<?php
echo "\n" . ' ';
if ($mergetable == TRUE) {
echo '<i>' . number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . '</i>' . "\n";
} else {
echo number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n";
}
?>
</td>
<td nowrap="nowrap">
&nbsp;<?php echo (isset($sts_data['Type']) ? $sts_data['Type'] : '&nbsp;'); ?>&nbsp;
</td>
<td align="right" nowrap="nowrap">
&nbsp;<?php echo $formated_size . ' ' . $unit . "\n"; ?>
</td>
<?php
} else {
?>
<td colspan="3" align="center">
<?php echo $strInUse . "\n"; ?>
</td>
<?php
}
echo "\n";
?>
</tr>
<?php
}
// Show Summary
list($sum_formated,$unit) = format_byte_down($sum_size,3,1);
echo "\n";
?>
<tr>
<th align="center">
&nbsp;<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>&nbsp;
</th>
<th align="right" nowrap="nowrap">
<b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
</th>
<th align="center">
<b>--</b>
</td>
<th align="right" nowrap="nowrap">
<b><?php echo $sum_formated . ' '. $unit; ?></b>
</th>
</tr>
</table>
<?php
} // end case mysql >= 3.23
// 3. Shows tables list mysql < 3.23
else {
$i = 0;
echo "\n";
?>
<!-- The tables list -->
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
<th><?php echo ucfirst($strRecords); ?></th>
</tr>
<?php
while ($i < $num_tables) {
$table = mysql_tablename($tables, $i);
$bgcolor = ($i % 2) ? $cfgBgcolorOne : $bgcolor = $cfgBgcolorTwo;
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td nowrap="nowrap">
<b><?php echo htmlspecialchars($table); ?>&nbsp;</b>
<b><?php echo htmlspecialchars($tables[$i]); ?>&nbsp;</b>
</td>
<td align="right" nowrap="nowrap">
&nbsp;<?php count_records($db, $table); ?>
&nbsp;<?php count_records($db, $tables[$i]); ?>
</td>
</tr>
<?php
@@ -61,7 +226,6 @@ else {
</table>
<?php
} // end if
mysql_free_result($tables);
/**

View File

@@ -6,12 +6,7 @@
* Gets the variables sent or posted to this script, then displays headers
*/
require('./grab_globals.inc.php3');
if (!isset($message)) {
include('./header.inc.php3');
} else {
show_message($message);
}
unset($sql_query);
require('./header.inc.php3');
/**
@@ -20,26 +15,78 @@ unset($sql_query);
mysql_select_db($db);
/**
* Gets table informations
*/
// The 'show table' statement works correct since 3.23.03
if (MYSQL_INT_VERSION >= 32303) {
$local_query = 'SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\'';
$result = mysql_query($local_query) or mysql_die('', $local_query);
$showtable = mysql_fetch_array($result);
$num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
$show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
} else {
$local_query = 'SELECT COUNT(*) AS count FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
$showtable = array();
$num_rows = mysql_result($result, 0, 'count');
$show_comment = '';
} // end display comments
mysql_free_result($result);
/**
* Gets table keys and retains them
*/
$local_query = 'SHOW KEYS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
$primary = '';
$prev_key = '';
$prev_seq = 0;
$i = 0;
$pk_array = array(); // will be use to emphasis prim. keys in the table view
while ($row = mysql_fetch_array($result)) {
$ret_keys[] = $row;
// Unset the 'Seq_in_index' value if it's not a composite index - part 1
if ($i > 0 && $row['Key_name'] != $prev_key && $prev_seq == 1) {
unset($ret_keys[$i-1]['Seq_in_index']);
}
$prev_key = $row['Key_name'];
$prev_seq = $row['Seq_in_index'];
// Backups the list of primary keys
if ($row['Key_name'] == 'PRIMARY') {
$primary .= $row['Column_name'] . ', ';
$pk_array[$row['Column_name']] = 1;
}
$i++;
} // end while
// Unset the 'Seq_in_index' value if it's not a composite index - part 2
if ($i > 0 && $row['Key_name'] != $prev_key && $prev_seq == 1) {
unset($ret_keys[$i-1]['Seq_in_index']);
}
mysql_free_result($result);
/**
* Gets fields properties
*/
$local_query = 'SHOW FIELDS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
$fields_cnt = mysql_num_rows($result);
/**
* Displays the comments of the table is MySQL >= 3.23
*/
if (MYSQL_INT_VERSION >= 32300) {
$local_query = 'SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\'';
$result = mysql_query($local_query) or mysql_die('', $local_query);
$row = mysql_fetch_array($result);
if (!empty($row['Comment'])) {
echo $strTableComments . '&nbsp;:&nbsp;' . $row['Comment'];
}
mysql_free_result($result);
} // end display comments
if (!empty($show_comment)) {
echo $strTableComments . '&nbsp;:&nbsp;' . $row['Comment'];
}
/**
* Displays the table structure
*/
// Gets fields properties
$local_query = 'SHOW FIELDS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
?>
<!-- TABLE INFORMATIONS -->
@@ -97,10 +144,14 @@ while ($row = mysql_fetch_array($result)) {
} else {
$row['Default'] = htmlspecialchars($row['Default']);
}
$field_name = htmlspecialchars($row['Field']);
if (isset($pk_array[$row['Field']])) {
$field_name = '<u>' . $field_name . '</u>';
}
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td nowrap="nowrap"><?php echo htmlspecialchars($row['Field']); ?>&nbsp;</td>
<td nowrap="nowrap"><?php echo $field_name; ?>&nbsp;</td>
<td<?php echo $type_nowrap; ?>><?php echo $type; ?></td>
<td nowrap="nowrap"><?php echo $strAttribute; ?></td>
<td><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
@@ -120,29 +171,75 @@ echo "\n";
/**
* Displays indexes
*/
$local_query = 'SHOW KEYS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
if (mysql_num_rows($result) > 0) {
$index_count = (isset($ret_keys))
? count($ret_keys)
: 0;
if ($index_count > 0) {
?>
<br /><br />
<!-- Indexes -->
<br />
<?php echo $strIndexes . '&nbsp;:' . "\n"; ?>
&nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo $strKeyname; ?></th>
<th><?php echo $strUnique; ?></th>
<th><?php echo $strField; ?></th>
</tr>
<?php
for ($i = 0 ; $i < mysql_num_rows($result); $i++) {
$row = mysql_fetch_array($result);
if (MYSQL_INT_VERSION >= 32323) {
echo "\n";
?>
<th><?php echo $strIdxFulltext; ?></th>
<?php
}
echo "\n";
?>
<th><?php echo $strField; ?></th>
</tr>
<?php
$prev_key = '';
$j = 0;
for ($i = 0 ; $i < $index_count; $i++) {
$row = $ret_keys[$i];
if (isset($row['Seq_in_index'])) {
$key_name = htmlspecialchars($row['Key_name']) . '<nobr>&nbsp;<small>-' . $row['Seq_in_index'] . '-</small></nobr>';
} else {
$key_name = htmlspecialchars($row['Key_name']);
}
if (!isset($row['Sub_part'])) {
$row['Sub_part'] = '';
}
if ($row['Key_name'] != $prev_key) {
$j++;
$prev_key = $row['Key_name'];
}
$bgcolor = ($j % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo;
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td><?php echo $key_name; ?></td>
<td><?php echo (($row['Non_unique'] == '0') ? $strYes : $strNo); ?></td>
<?php
if (MYSQL_INT_VERSION >= 32323) {
echo "\n";
?>
<td><?php echo (($row['Comment'] == 'FULLTEXT') ? $strYes : $strNo); ?></td>
<?php
}
if (!empty($row['Sub_part'])) {
echo "\n";
?>
<td><?php echo htmlspecialchars($row['Column_name']); ?></td>
<td align="right">&nbsp;<?php echo $row['Sub_part']; ?></td>
<?php
} else {
echo "\n";
?>
<td colspan="2"><?php echo htmlspecialchars($row['Column_name']); ?></td>
<?php
}
echo "\n";
?>
<tr>
<td><?php echo htmlspecialchars($row['Key_name']) . "\n"; ?></td>
<td><?php echo (($row['Non_unique'] == '0') ? $strYes : $strNo) . "\n"; ?></td>
<td><?php echo htmlspecialchars($row['Column_name']) . "\n"; ?></td>
</tr>
<?php
} // end for
@@ -150,8 +247,187 @@ if (mysql_num_rows($result) > 0) {
?>
</table>
<?php
} // end if
mysql_free_result($result);
echo "\n";
} // end display indexes
/**
* Displays Space usage and row statistics
*
* staybyte - 9 June 2001
*/
$nonisam = FALSE;
if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
$nonisam = TRUE;
}
if (MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
// Gets some sizes
$mergetable = FALSE;
if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
$mergetable = TRUE;
}
list($data_size, $data_unit) = format_byte_down($showtable['Data_length']);
if ($mergetable == FALSE) {
list($index_size, $index_unit) = format_byte_down($showtable['Index_length']);
}
if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
list($free_size, $free_unit) = format_byte_down($showtable['Data_free']);
list($effect_size, $effect_unit) = format_byte_down($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
} else {
list($effect_size, $effect_unit) = format_byte_down($showtable['Data_length'] + $showtable['Index_length']);
}
list($tot_size, $tot_unit) = format_byte_down($showtable['Data_length'] + $showtable['Index_length']);
if ($num_rows > 0) {
list($avg_size, $avg_unit) = format_byte_down(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
}
// Displays them
?>
<br /><br />
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- Space usage -->
<td valign="top">
&nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo $strType; ?></th>
<th colspan="2" align="center"><?php echo $strUsage; ?></th>
</tr>
<tr bgcolor="<?php echo $cfgBgcolorTwo; ?>">
<td style="padding-right: 10px"><?php echo ucfirst($strData); ?></td>
<td align="right" nowrap="nowrap"><?php echo $data_size; ?></td>
<td><?php echo $data_unit; ?></td>
</tr>
<?php
if (isset($index_size)) {
echo "\n";
?>
<tr bgcolor="<?php echo $cfgBgcolorTwo; ?>">
<td style="padding-right: 10px"><?php echo ucfirst($strIndex); ?></td>
<td align="right" nowrap="nowrap"><?php echo $index_size; ?></td>
<td><?php echo $index_unit; ?></td>
</tr>
<?php
}
if (isset($free_size)) {
echo "\n";
?>
<tr bgcolor="<?php echo $cfgBgcolorTwo; ?>" style="color: #bb0000">
<td style="padding-right: 10px"><?php echo ucfirst($strOverhead); ?></td>
<td align="right" nowrap="nowrap"><?php echo $free_size; ?></td>
<td><?php echo $free_unit; ?></td>
</tr>
<tr bgcolor="<?php echo $cfgBgcolorOne; ?>">
<td style="padding-right: 10px"><?php echo ucfirst($strEffective); ?></td>
<td align="right" nowrap="nowrap"><?php echo $effect_size; ?></td>
<td><?php echo $effect_unit; ?></td>
</tr>
<?php
}
if (isset($tot_size) && $mergetable == FALSE) {
echo "\n";
?>
<tr bgcolor="<?php echo $cfgBgcolorOne; ?>">
<td style="padding-right: 10px"><?php echo ucfirst($strTotal); ?></td>
<td align="right" nowrap="nowrap"><?php echo $tot_size; ?></td>
<td><?php echo $tot_unit; ?></td>
</tr>
<?php
}
echo "\n";
?>
</table>
</td>
<td width="20">&nbsp;</td>
<!-- Rows Statistic -->
<td valign="top">
&nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo $strStatement; ?></th>
<th align="center"><?php echo $strValue; ?></th>
</tr>
<?php
$i = 0;
if (isset($showtable['Row_format'])) {
echo "\n";
?>
<tr bgcolor="<?php echo ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne); ?>">
<td><?php echo ucfirst($strFormat); ?></td>
<td align="right" nowrap="nowrap">
<?php
echo ' ';
if ($showtable['Row_format'] == 'Fixed') {
echo $strFixed;
} else if ($showtable['Row_format'] == 'Dynamic') {
echo $strDynamic;
} else {
echo $showtable['Row_format'];
}
echo "\n";
?>
</td>
</tr>
<?php
}
if (isset($showtable['Rows'])) {
echo "\n";
?>
<tr bgcolor="<?php echo ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne); ?>">
<td><?php echo ucfirst($strRows); ?></td>
<td align="right" nowrap="nowrap">
<?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
</td>
</tr>
<?php
}
if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
echo "\n";
?>
<tr bgcolor="<?php echo ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne); ?>">
<td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
<td align="right" nowrap="nowrap">
<?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
</td>
</tr>
<?php
}
if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
echo "\n";
?>
<tr bgcolor="<?php echo ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne); ?>">
<td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
<td align="right" nowrap="nowrap">
<?php echo "$avg_size $avg_unit\n"; ?>
</td>
</tr>
<?php
}
if (isset($showtable['Auto_increment'])) {
echo "\n";
?>
<tr bgcolor="<?php echo ((++$i%2) ? $cfgBgcolorTwo : $cfgBgcolorOne); ?>">
<td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
<td align="right" nowrap="nowrap">
<?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
</td>
</tr>
<?php
}
echo "\n";
?>
</table>
</td>
</tr>
</table>
<?php
} // end if (MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
/**