5

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

0

6 Answers 6

16
$result = mysqli_query($db_conn,"SHOW DATABASES"); 
while ($row = mysqli_fetch_array($result)) { 
    echo $row[0]."<br>"; 
}
Sign up to request clarification or add additional context in comments.

1 Comment

^^ thumbs up. for mysqli.. $result = mysqli_query($db_conn,"SHOW DATABASES"); while ($row = mysqli_fetch_array($result)) { echo $row[0]."<br>"; }
1
$dbcnx = mysql_connect ($dbhost, $dbusername, $dbpassword); 
$result = @mysql_query('SHOW DATABASES'); 

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

Comments

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.

Comments

-2

The MySQL command for this is

SHOW DATABASES

See the manual for more info on the SHOW command

Comments

-2

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

Comments

-2

Write the SQL query:

  show databases

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.