mysql_list_tables获取数据库中所有表
mysql_list_tables介绍
resource mysql_list_tables ( string data [, resource _identifier] )
mysql_list_tables() 接受一个数据库名并返回和 mysql_query() 函数很相似的一个结果指针。用 mysql_tablename() 函数来遍历此结果指针,或者任何使用结果表的函数,例如 mysql_fetch_array()。
data 参数是需要被取得其中的的表名的数据库名。如果失败 mysql_list_tables() 返回 FALSE。
为向下兼容仍然可以使用本函数的别名 mysql_listtables(),但反对这样做。
注: 该函数已经被删除了,请不要再使用该函数。您可以用命令 SHOW TABLES FROM DATA 来实现该函数的功能。
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 tables\\n\";
print \'MySQL Error: \' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
print \"Table: $row[0]\\n\";
}
mysql_free_result($result);
?>
上面已经说过,mysql_list_tables()函数已经被删除了,所以上面实例会报错:
Deprecated: Function mysql_list_tables() is deprecated
正确的方法是使用mysql_query("SHOW TABLES FROM $data ")代替mysql_list_tables()函数。
<?php
mysql_connect(\"127.0.0.1\",\"root\",\"password\");
$tables = mysql_query(\"SHOW TABLES FROM information_schema\");
while (list($table) = mysql_fetch_row($tables)) {
echo \"$table <br />\";
}
?> 继续阅读与本文标签相同的文章
-
苹果和Facebook竟因为一处房产而掐架
2026-05-14栏目: 教程
-
Windows 10 1909预计推送时间为11月12日
2026-05-14栏目: 教程
-
关于第四次工业革命的一些思考
2026-05-14栏目: 教程
-
HTTPS安全通信基础
2026-05-14栏目: 教程
-
Google Books迎15岁生日,官方优化细节设计暗藏“小心机”
2026-05-14栏目: 教程
