You can retrieve databases in your mysql server using php. On mysql server, you can use mysql query in order to get databases in mysql.
SHOW DATABASES
It displays database list in mysql as like below:
Now you can find the database list in mysql server using php scripts:
OR
<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list))
{
echo $row->Database . "<br>";
}
?>
Now you'll get output like below:
Related Post:
Get database list using mysql query:
The following mysql query is used to display database list.SHOW DATABASES
It displays database list in mysql as like below:
Get database list in mysql using php:
You can display database list in mysql using php in two ways.
1. Display database list using php and mysql query
2. Display database list using php and mysql_list_tables()
Display database list using php and mysql:
<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
$result = mysql_query("SHOW DATABASES") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row[0]."<br>";
}
?>
$link=mysql_connect('localhost','root','') or die(mysql_error());
$result = mysql_query("SHOW DATABASES") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo $row[0]."<br>";
}
?>
OR
Display databases in mysql using php and mysql_list_dbs():
The php code for display database list:
<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list))
{
echo $row->Database . "<br>";
}
?>
Now you'll get output like below:
Related Post: