Listing Tables in a Database : Table Database « MySQL Database « PHP






Listing Tables in a Database


<?
$connection = @mysql_connect("mysql153.secureserver.net", "java2s", "password") or die(mysql_error());

//get database list
$dbs = @mysql_list_dbs($connection) or die(mysql_error());

//start first bullet list
$db_list = "<ul>";
$db_num = 0;

while ($db_num < mysql_num_rows($dbs)) {
     $db_names[$db_num] = mysql_tablename($dbs, $db_num);
     $db_list .= "<li>$db_names[$db_num]";

     //get table names and start another bullet list
     $tables = @mysql_list_tables($db_names[$db_num]) or die(mysql_error());
     $table_list = "<ul>";
     $table_num = 0;

     while ($table_num < mysql_num_rows($tables)) {
          //get table names and make each a bullet point
          $table_names[$table_num] = mysql_tablename($tables, $table_num);
          $table_list .= "<li>$table_names[$table_num]";
          $table_num++;
     }
     $table_list .= "</ul>";
     $db_list .= "$table_list";
     $db_num++;
}
$db_list .= "</ul>";
?>
<HTML>
<HEAD>
<TITLE>MySQL Tables</TITLE>
</HEAD>
<BODY>
<P><strong>Databases and tables in a MySQL database</strong>:</P>
<? echo "$db_list"; ?>
</BODY>
</HTML>
           
       








Related examples in the same category

1.Get all tables in a database