How can I Print All MySQL Database Tables & Fields Using PHP?

<?php
/****************
* File: displaytables.php
* Date: 1.13.2009
* Author: design1online.com
* Purpose: display all table structure for a specific database
****************/

//connection variables
$host = “localhost”;
$database = “your_db_name”;
$user = “your_username”;
$pass = “your_pass”;

//connection to the database
mysql_connect($host, $user, $pass)
or die (‘cannot connect to the database: ‘ . mysql_error());

//select the database
mysql_select_db($database)
or die (‘cannot select database: ‘ . mysql_error());

//loop to show all the tables and fields
$loop = mysql_query(“SHOW tables FROM $database”)
or die (‘cannot select tables’);

while($row = mysql_fetch_array($loop))
{

echo “
<table cellpadding=2 cellspacing=2 border=0 width=75%>
<tr bgcolor=#666666>
<td colspan=5><center><b><font color=#FFFFFF>” . $row[0] . “</font></center></td>
</tr>
<tr>
<td>Field</td><td>Type</td><td>Key</td><td>Default</td><td>Extra</td>
</tr>”;

$i = 0;

$loop2 = mysql_query(“SHOW columns FROM ” . $row[0])
or die (‘cannot select table fields’);

while ($row2 = mysql_fetch_array($loop2))
{
echo “<tr “;
if ($i % 2 == 0)
echo “bgcolor=#CCCCCC”;
echo “><td>” . $row2[0] . “</td><td>” . $row2[1] . “</td><td>” . $row2[2] . “</td><td>” . $row2[3] . “</td><td>” . $row2[4] . “</td></tr>”;
$i++;
}
echo “</table><br/><br/>”;

}
?>

Reference : http://jadendreamer.wordpress.com/2009/01/13/print-all-mysql-database-tables-fields-using-php/

thanks above content for the above url.

Leave a Reply

© 2020 Spirituality