How can I get a list of all the MySQL databases that exist on a server using PHP?
6 Answers
$result = mysqli_query($db_conn,"SHOW DATABASES");
while ($row = mysqli_fetch_array($result)) {
echo $row[0]."<br>";
}
1 Comment
James Walker
^^ thumbs up. for mysqli..
$result = mysqli_query($db_conn,"SHOW DATABASES"); while ($row = mysqli_fetch_array($result)) { echo $row[0]."<br>"; }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.