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); ?>
輸出類似:
mysql test test_db