(PHP 4, PHP 5)
mysql_list_tables — 列出 MySQL 數(shù)據(jù)庫中的表
說明
resource mysql_list_tables ( string$database
[, resource $link_identifier
] )
mysql_list_tables() 接受一個(gè)數(shù)據(jù)庫名并返回和 mysql_query() 函數(shù)很相似的一個(gè)結(jié)果指針。用 mysql_tablename() 函數(shù)來遍歷此結(jié)果指針,或者任何使用結(jié)果表的函數(shù),例如 mysql_fetch_array()。
database
參數(shù)是需要被取得其中的的表名的數(shù)據(jù)庫名。如果失敗
mysql_list_tables() 返回 FALSE
。
為向下兼容仍然可以使用本函數(shù)的別名 mysql_listtables(),但反對這樣做。
Note: 該函數(shù)已經(jīng)被刪除了,請不要再使用該函數(shù)。您可以用命令 SHOW TABLES FROM DATABASE 來實(shí)現(xiàn)該函數(shù)的功能。
Example #1 mysql_list_tables() 例子
<?php
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
print 'Could not connect to mysql';
exit;
}
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tablesn";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
print "Table: $row[0]n";
}
mysql_free_result($result);
?>
參見 mysql_list_dbs() 和 mysql_tablename()。