PHP - get list of database names
How can I get a list of all MySQL databases existing on the server using PHP?
+3
some Folk
source
to share
6 answers
$result = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_array($result)) {
echo $row[0]."<br>";
}
+12
Sergey Studenikin
source
to share
$dbcnx = mysql_connect ($dbhost, $dbusername, $dbpassword);
$result = @mysql_query('SHOW DATABASES');
while ($row = mysql_fetch_array($result)) {
print_r ($row)
}
+2
Tamik Soziev
source
to share
In MySQL, the prompt SHOW DATABASES
does what you want.
You can run this command as a query from PDO or MySQL's own PHP library and read the returned rows. Imagine this is a common choice.
You will only see the databases that the account used to connect to MySQL can see.
0
jjohn
source
to share
MySQL command for this
SHOW DATABASES
For more information on the SHOW command, see the manual .
-1
liquorvicar
source
to share
Write your SQL query :
show databases
-1
kasavbere
source
to share
Just use SHOW DATABASES
. It will show all the databases you have in your MySQL.
-1
NewUser
source
to share