'PHP - Get list of databases names [duplicate]

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



Solution 1:[1]

$result = mysqli_query($db_conn,"SHOW DATABASES"); 
while ($row = mysqli_fetch_array($result)) { 
    echo $row[0]."<br>"; 
}

Solution 2:[2]

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

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

Solution 3:[3]

At the MySQL prompt, SHOW DATABASES does what you want.

You can run this command as a query from PDO or the native PHP MySQL library and read the returned rows. Pretend it is a normal select.

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

Solution 4:[4]

The MySQL command for this is

SHOW DATABASES

See the manual for more info on the SHOW command

Solution 5:[5]

Just use SHOW DATABASES.It will show all the databases present in your MySQL.

Solution 6:[6]

Write the SQL query:

  show databases

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Tamik Soziev
Solution 3 Peter Mortensen
Solution 4 liquorvicar
Solution 5 NewUser
Solution 6 Peter Mortensen