note 17779 deleted from function.mysql-query by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 01:00:12 +0000 |
| Subject: | note 17779 deleted from function.mysql-query by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24071@lists.php.net to get a copy of this message | ||
It's often useful to know what is in the database, so here's a simple way to do it:
function readDB($connection , $dbname){
$tableNames = mysql_list_tables($dbname, $connection);
while ($i < mysql_num_rows($tableNames)) {
$table = mysql_tablename($tableNames, $i);
$result = mysql_query("SELECT * FROM $table;", $connection);
if (strlen($result) > 0) {
$num_fields = @mysql_num_fields ($result);
echo "<table border=0 align=center>\n";
$x = 0; $output = "";
while ($field = @mysql_fetch_field ($result)) {
if (@mysql_num_rows ($result) > 0) {
$output .= "<td><B> $field->name </B></td>\n";
$x++;
}
}
echo "<TR><TD COLSPAN=$x ALIGN=middle><FONT
SIZE=7>$table</FONT></TD></TR>";
echo " <tr bgcolor=\"#840000\">\n$output</tr>\n";
while ($row = mysql_fetch_row ($result)) {
($bgcolor == "#365C36") ? $bgcolor = "#00366C" : $bgcolor =
"#365C36";
echo " <tr bgcolor=$bgcolor>\n";
for ($j=0; $j < $num_fields; $j++) {
echo " <td> ".htmlspecialchars($row[$j])." </td>\n";
}
echo " </tr>\n";
}
echo "</table>\n";
}
$i++;
}
}