PHP mysql_list_dbs() 函数
定义和用法
mysql_list_dbs() 函数列出 MySQL 服务器中所有的数据库。
语法
mysql_list_dbs(connection)
| 参数 | 描述 |
|---|---|
| connection | 可选。规定 SQL 连接标识符。如果未规定,则使用上一个打开的连接。 |
说明
mysql_list_dbs() 将返回一个结果指针,包含了当前 MySQL 进程中所有可用的数据库。
用 mysql_tablename() 函数来遍历此结果指针,或者任何使用结果表的函数,例如 mysql_fetch_array()。
例子
<?php$con = mysql_connect("localhost", "hello", "321");if (!$con){die('Could not connect: ' . mysql_error());}$db_list = mysql_list_dbs($con);while ($db = mysql_fetch_object($db_list)){echo $db->Database . "<br />";}mysql_close($con);?>
输出类似:
mysqltesttest_db