How can I get a list of all the MySQL databases that exist on a server using PHP?
Asked
Active
Viewed 2.4k times
6 Answers
16
$result = mysqli_query($db_conn,"SHOW DATABASES");
while ($row = mysqli_fetch_array($result)) {
echo $row[0]."<br>";
}
Dharman
- 26,923
- 21
- 73
- 125
Сергей Студеникин
- 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
- 13,578
- 5
- 40
- 54
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,030
- 21
- 100
- 124
jjohn
- 9,130
- 4
- 22
- 21
-2
Just use SHOW DATABASES.It will show all the databases present in your MySQL.
NewUser
- 12,175
- 36
- 139
- 230
"; }` – James Walker Jan 28 '18 at 21:40