PHP mysql_list_dbs() Function
Definition and Usage
The mysql_list_dbs() function lists all the databases in the MySQL server.
Syntax
mysql_list_dbs(connection)
Parameter | Description |
---|---|
connection | Optional. Specifies the SQL connection identifier. If not specified, the last opened connection is used. |
Description
mysql_list_dbs() will return a result pointer that contains all the available databases in the current MySQL process.
Use the mysql_tablename() function to iterate over this result pointer, or any function that uses a result table, such as mysql_fetch_array().
Example
<?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); ?>
Output similar to:
mysql test test_db