<?php
$HOSTNAME = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DBNAME = 'rizvi_test_db';
mysql_select_db($DBNAME, mysql_connect($HOSTNAME, $USERNAME, $PASSWORD)) or die(mysql_error());
$result = mysql_query("SHOW TABLES;") or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row[0]; //print the table name
$result2 = mysql_query("DESCRIBE ".$row[0].";") or die(mysql_error()); //get details schema for each table
echo "<table border='1' width='70%'>";
echo "<tr><td>Field</td><td>Type</td><td>Null</td><td>Key</td><td>Default</td><td>Extra</td>";
while($row2 = mysql_fetch_array($result2)){
for($i=0; $i<6; $i++){
if($row2[$i] == "" || $row2[$i] == NULL){
$row2[$i] = " ";
}
}
echo "<tr>";
echo "<td>".$row2[0]."</td><td>".$row2[1]."</td><td>".$row2[2]."</td><td>".$row2[3]."</td><td>".$row2[4]."</td><td>".$row2[5];
echo "</tr>";
}
echo "</table>";
echo "<br/>";
}
?>
Monday, September 13, 2010
Print Mysql Database Structure Using PHP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment