PHP/MySQL Database/Table Database

Материал из Web эксперт
Перейти к: навигация, поиск

Get all tables in a database

<?php
   mysql_connect("mysql153.secureserver.net","wbex","password");
   $tables = mysql_list_tables("wbex");
   $count = 0;
   while ($count < mysql_numrows($tables)) {
      echo mysql_tablename($tables,$count)."<br />";
      $count++;
   }
?>



Listing Tables in a Database

<?
$connection = @mysql_connect("mysql153.secureserver.net", "wbex", "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>