mysql_list_dbs
Lists all databases in the MySQL server.
Function name: mysql_list_dbs()
Function Applicable Version: PHP 5.5.0 - PHP 5.6.x
Function usage: The mysql_list_dbs() function is used to get a list of all databases in the current database connection.
Syntax: resource mysql_list_dbs ( [resource $link_identifier = NULL] )
Parameters: $link_identifier (optional): MySQL connection identifier. If not provided, the last open database connection is used by default.
Return value: On success, return a MySQL result resource containing all database lists in the current database connection; on failure, return FALSE.
Example:
<?php // 创建数据库连接 $link = mysql_connect('localhost', 'username', 'password'); // 检查连接是否成功 if (!$link) { die('数据库连接失败: ' . mysql_error()); } // 获取数据库列表 $result = mysql_list_dbs($link); // 检查结果是否为空 if (!$result) { die('无法获取数据库列表: ' . mysql_error()); } // 打印数据库列表 while ($row = mysql_fetch_object($result)) { echo $row---> Database . "\n"; } // Release the result resource mysql_free_result($result); // Close the database connection mysql_close($link); ?>Notes: