Hi all,
I have a real old mysql database, I've been throwing stuff at it for so long I couldn't remember what I had in it.
Using the command line to go through it all was taking forever and not really showing me the info that was there.
I made the following page to get all the names of the databases, and tables within them into select boxes and then display the data held in each when selected.
Now with a couple of clicks I can explore my mySQL databases easily.
Just thought others here may find it useful.
Feel free to post any bugs or suggestions and I'll chang it if it seems like a good idea.
Currently developed on PHP version 4.0.6
----------------mysqlexplore.php----------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>mySQL Explorer - Version: 1.0</title>
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"
bgcolor="#ffffff" text="#000000" link="#000099" alink="#0000ff"
vlink="#000099">
<?php
//////////////////////////////////////////////////////////////////////////////////
// //
// mySQL Explorer version 1 Copyright Karv@virtualkev.com //
// //
// Written : 16th June 2002 //
// Last modified: never //
// Bugs : none it seems (yet) //
// //
//////////////////////////////////////////////////////////////////////////////////
// Database connection details - CHANGE THESE AS NECESSARY //
$host="localhost";
$user="root";
$password="";
//////////////////////////////////////////////////////////////////////////////////
// You should not need to edit anything below here unless you use PHP Version > 4.0.6
// and are experiencing problems. If so please email me details or problems to fix.
//////////////////////////////////////////////////////////////////////////////////
// connect
$connection=@mysql_connect($host,$user,$password) ;
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
// start the page
echo "<table border=0 width=100% cellspacing=1 cellpadding=0>\n";
echo "<tr bgcolor=#0099cc>\n<td wdith=34%>\n";
// find databases;
echo "<form name=select_db action=$PHP_SELF>\n";
$db_list = mysql_list_dbs($connection);
echo " <select name=db>\n";
echo "<option>Select database</option>\n";
while ($row = mysql_fetch_row($db_list)) {
if($row[0] == $db){
echo"<option value=$row[0] selected>$row[0]</option>\n";
}else{
echo"<option value=$row[0]>$row[0]</option>\n";
}
}
mysql_free_result($db_list);
echo "<input type=submit name=setdb value=\"use database\"></select>\n</form>\n";
// unset $table when changing database to avoid running invalid queries
if(isset($setdb)){
unset($table);
}
// find tables if database selected or don't show it
if(isset($db)){
echo "<form name=select_table action=$PHP_SELF>";
$table_list = mysql_list_tables($db);
echo " <select name=table>\n";
echo "<option>Select Table</option>\n";
while ($row = mysql_fetch_row($table_list)) {
if($row[0] == $table){
echo"<option value=$row[0] selected>$row[0]</option>\n";
}else{
echo"<option value=$row[0]>$row[0]</option>\n";
}
}
echo "<input type=hidden name=db value=$db>\n";
echo "<input type=submit value=\"use table\">\n</select>\n</form>\n";
}
// finish the title table
echo "</td><td width=33%>\n";
echo "<div align=center><h2> mySQL Explorer Version 1.0</h2></div>";
echo "</td><td width=33%>\n";
printf ("<div align=center><h3>MySQL server version: %s </h3></div><br>", mysql_get_server_info());
printf ("<div align=center><h3>PHP version: %s </h3></div>", phpversion());
echo "</td></tr>\n</table>\n";
// set the bd after selection only
if(isset($db)){
@mysql_select_db($db,$connection) ;
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
}
// get the tables from the database once its been selected
if(isset($table)){
// query stuff - used to get all items from the db but you can limit it here
$fields="*";
$sql="SELECT $fields from $table";
// run query
$result=@mysql_query($sql,$connection);
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
$columns=@mysql_num_fields($result);
// start the table
echo "<table border=0 cellspacing=1 cellpadding=0>\n";
// figure out how many columns are in it and do the table to fit.
$res_rows=mysql_num_rows($result);
echo "Displaying <b>$res_rows</b> rows:<br>";
$row=0;
while ($myrow = @mysql_fetch_array($result)){
$row++;
if($row%2){
$color="#999999";
}else{
$color="#599999";
}
echo "<tr>";
for ($i = 0; $i < ($columns); $i++) {
echo "<td bgcolor=$color> $myrow[$i] </td>";
}
echo "</tr>\n";
}
echo "</table>";
}
?>
***************************************
Party on, dudes!
I have a real old mysql database, I've been throwing stuff at it for so long I couldn't remember what I had in it.
Using the command line to go through it all was taking forever and not really showing me the info that was there.
I made the following page to get all the names of the databases, and tables within them into select boxes and then display the data held in each when selected.
Now with a couple of clicks I can explore my mySQL databases easily.
Just thought others here may find it useful.
Feel free to post any bugs or suggestions and I'll chang it if it seems like a good idea.
Currently developed on PHP version 4.0.6
----------------mysqlexplore.php----------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>mySQL Explorer - Version: 1.0</title>
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"
bgcolor="#ffffff" text="#000000" link="#000099" alink="#0000ff"
vlink="#000099">
<?php
//////////////////////////////////////////////////////////////////////////////////
// //
// mySQL Explorer version 1 Copyright Karv@virtualkev.com //
// //
// Written : 16th June 2002 //
// Last modified: never //
// Bugs : none it seems (yet) //
// //
//////////////////////////////////////////////////////////////////////////////////
// Database connection details - CHANGE THESE AS NECESSARY //
$host="localhost";
$user="root";
$password="";
//////////////////////////////////////////////////////////////////////////////////
// You should not need to edit anything below here unless you use PHP Version > 4.0.6
// and are experiencing problems. If so please email me details or problems to fix.
//////////////////////////////////////////////////////////////////////////////////
// connect
$connection=@mysql_connect($host,$user,$password) ;
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
// start the page
echo "<table border=0 width=100% cellspacing=1 cellpadding=0>\n";
echo "<tr bgcolor=#0099cc>\n<td wdith=34%>\n";
// find databases;
echo "<form name=select_db action=$PHP_SELF>\n";
$db_list = mysql_list_dbs($connection);
echo " <select name=db>\n";
echo "<option>Select database</option>\n";
while ($row = mysql_fetch_row($db_list)) {
if($row[0] == $db){
echo"<option value=$row[0] selected>$row[0]</option>\n";
}else{
echo"<option value=$row[0]>$row[0]</option>\n";
}
}
mysql_free_result($db_list);
echo "<input type=submit name=setdb value=\"use database\"></select>\n</form>\n";
// unset $table when changing database to avoid running invalid queries
if(isset($setdb)){
unset($table);
}
// find tables if database selected or don't show it
if(isset($db)){
echo "<form name=select_table action=$PHP_SELF>";
$table_list = mysql_list_tables($db);
echo " <select name=table>\n";
echo "<option>Select Table</option>\n";
while ($row = mysql_fetch_row($table_list)) {
if($row[0] == $table){
echo"<option value=$row[0] selected>$row[0]</option>\n";
}else{
echo"<option value=$row[0]>$row[0]</option>\n";
}
}
echo "<input type=hidden name=db value=$db>\n";
echo "<input type=submit value=\"use table\">\n</select>\n</form>\n";
}
// finish the title table
echo "</td><td width=33%>\n";
echo "<div align=center><h2> mySQL Explorer Version 1.0</h2></div>";
echo "</td><td width=33%>\n";
printf ("<div align=center><h3>MySQL server version: %s </h3></div><br>", mysql_get_server_info());
printf ("<div align=center><h3>PHP version: %s </h3></div>", phpversion());
echo "</td></tr>\n</table>\n";
// set the bd after selection only
if(isset($db)){
@mysql_select_db($db,$connection) ;
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
}
// get the tables from the database once its been selected
if(isset($table)){
// query stuff - used to get all items from the db but you can limit it here
$fields="*";
$sql="SELECT $fields from $table";
// run query
$result=@mysql_query($sql,$connection);
$err_no=mysql_errno();
if ($err_no > 0 ){
echo "<h2> Error:</h1> " . mysql_errno() . ": " . mysql_error() . "<br>";
exit;
}
$columns=@mysql_num_fields($result);
// start the table
echo "<table border=0 cellspacing=1 cellpadding=0>\n";
// figure out how many columns are in it and do the table to fit.
$res_rows=mysql_num_rows($result);
echo "Displaying <b>$res_rows</b> rows:<br>";
$row=0;
while ($myrow = @mysql_fetch_array($result)){
$row++;
if($row%2){
$color="#999999";
}else{
$color="#599999";
}
echo "<tr>";
for ($i = 0; $i < ($columns); $i++) {
echo "<td bgcolor=$color> $myrow[$i] </td>";
}
echo "</tr>\n";
}
echo "</table>";
}
?>
***************************************
Party on, dudes!