PHP/MySQL Database/Table Database — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
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>