How can I get a list of all the MySQL databases that exist on a server using PHP?
Asked
Active
Viewed 2.6k times
6 Answers
16
$result = mysqli_query($db_conn,"SHOW DATABASES");
while ($row = mysqli_fetch_array($result)) {
echo $row[0]."<br>";
}

Dharman
- 30,962
- 25
- 85
- 135

Сергей Студеникин
- 370
- 2
- 8
1
$dbcnx = mysql_connect ($dbhost, $dbusername, $dbpassword);
$result = @mysql_query('SHOW DATABASES');
while ($row = mysql_fetch_array($result)) {
print_r ($row)
}

Tamik Soziev
- 14,307
- 5
- 43
- 55
0
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.

Peter Mortensen
- 30,738
- 21
- 105
- 131

jjohn
- 9,708
- 4
- 20
- 21
-2
Just use SHOW DATABASES
.It will show all the databases present in your MySQL.

NewUser
- 12,713
- 39
- 142
- 236
"; }` – James Walker Jan 28 '18 at 21:40