How to get a list of databases?

It doesn't appear as though there's a function available to do this, but you can execute a show databases; query and the rows returned will be the databases available.

EXAMPLE:

Replace this:

$db_list = mysql_list_dbs($link); //mysql 

With this:

$db_list = mysqli_query($link, "SHOW DATABASES"); //mysqli

I realize this is an old thread but, searching the 'net still doesn't seem to help. Here's my solution;

$sql="SHOW DATABASES";
$link = mysqli_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql: ' . mysqli_error($link).'\r\n');

if (!($result=mysqli_query($link,$sql))) {
        printf("Error: %s\n", mysqli_error($link));
    }

while( $row = mysqli_fetch_row( $result ) ){
        if (($row[0]!="information_schema") && ($row[0]!="mysql")) {
            echo $row[0]."\r\n";
        }
    }

Tags:

Mysql

Php

Mysqli