PHP : mysql_list_dbs() function
Description
The mysql_list_dbs() is used to fetch a list of the databases available for a given connection.
Version
(PHP 4 and above)
Syntax
mysql_list_dbs(connection )
Parameter
| Name | Description | Required/ Optional | Type |
|---|---|---|---|
| connection | The MySQL connection. Before performing any operation on a MySQL database, it is required to set a connection to the mysql database you want to work with. And this is done by mysql_connect() function. This function takes three parameters, name of the host, username with which you want to perform tasks with the mysql database in question, and password of that user. As soon as a successful connection is established, you can perform the operations on that mysql database. In case, no such connection is found, it will try to create one without any arguments, i.e. mysql_connect() without any parameters. If it fails to connect to a mysql database, it will generate a warning (E_WARNING) but not an error. | Optional | Resource |
Return value
MySQL result handle on success; FALSE on failure.
Value Type : Resource.
Example :
<?php
$con = mysql_connect("localhost", "root", "mypass");
$selectdb = mysql_select_db("tutorials",$con);
$db_list = mysql_list_dbs($con);
echo "<h2>Here is a list of the databases present in the system : </h2>";
while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "<br />";
}
?>
Output :
Here is a list of the databases present in the system :
information_schema
bookinfo
bupayroll
my_db
mysql
student
test
Note
Depending upon the databases available on your MySQL Server, output may vary.
See also

