PHP – Listing the Databases Available in a Connection

The given PHP example helps you to listing the databases available in a connection.

Code Example:
$user = "root";
$pass = "root";
$link =  mysql_connect($hostname, $user, $pass );
if(!$link) die( "Couldn't connect to MySQL" );

$db_res = mysql_list_dbs( $link );
$num = mysql_num_rows( $db_res );

for( $i = 0; $i < $num; $i++ )
    print mysql_tablename( $db_res, $i )."<br>";

mysql_close( $link );

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *