PHP mysql_list_dbs() 函數(shù)
定義和用法
mysql_list_dbs() 函數(shù)列出 MySQL 服務(wù)器中所有的數(shù)據(jù)庫。
語法
mysql_list_dbs(connection)
參數(shù) | 描述 |
---|---|
connection | 可選。規(guī)定 SQL 連接標(biāo)識(shí)符。如果未規(guī)定,則使用上一個(gè)打開的連接。 |
說明
mysql_list_dbs() 將返回一個(gè)結(jié)果指針,包含了當(dāng)前 MySQL 進(jìn)程中所有可用的數(shù)據(jù)庫。
用 mysql_tablename() 函數(shù)來遍歷此結(jié)果指針,或者任何使用結(jié)果表的函數(shù),例如 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