mysql_list_dbs() function in PHP

What is mysql_list_dbs() function in PHP?
How does mysql_list_dbs() works?


This mysql_list_dbs() function fetches a list of the databases available on a MySQL server for a given connection and returns a result pointer containing the databases available from the current mysql connection.
resource mysql_list_dbs ( [resource link_identifier])

Returns a result pointer containing the available databases on success, or FALSE on failure.

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
//Returns result pointer containing available databases
$db_list = mysql_list_dbs($link);
//print each database returned by mysql_list_dbs function
while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "n";

Above code fetches list of database using mysql_list_dbs function on a MySQL server for a given connection $link. mysql_fetch_object function is used to fetch and display each database returned by the result pointer of mysql_list_dbs function.

See also: mysql_db_name().

PHP Topics

Ask Questions

Ask Question