PHP - get list of database names

How can I get a list of all MySQL databases existing on the server using PHP?

+3


source to share


6 answers


$result = mysql_query("SHOW DATABASES");        
while ($row = mysql_fetch_array($result)) {        
    echo $row[0]."<br>";        
}

      



+12


source


$dbcnx = mysql_connect ($dbhost, $dbusername, $dbpassword); 
$result = @mysql_query('SHOW DATABASES'); 

while ($row = mysql_fetch_array($result)) { 
 print_r ($row)
} 

      



+2


source


In MySQL, the prompt SHOW DATABASES

does what you want.

You can run this command as a query from PDO or MySQL's own PHP library and read the returned rows. Imagine this is a common choice.

You will only see the databases that the account used to connect to MySQL can see.

0


source


MySQL command for this

SHOW DATABASES

      

For more information on the SHOW command, see the manual .

-1


source


Write your SQL query :

  show databases

      

-1


source


Just use SHOW DATABASES

. It will show all the databases you have in your MySQL.

-1


source







All Articles