PHP MySQL Functions to list databases

WE can use PHP PDO to list databases existing in MySQL. Here is the query
SHOW DATABASES
Using the above query we will develop a PHP PDO script to display all the databases present . Here is the code.
<?Php
////////////////
require "config.php"; // Database Connection
////////////////
$result = $dbo->query("SHOW DATABASES");
while ($row = $result->fetch(PDO::FETCH_NUM)) {
echo $row[0]."<br>";
}
?>
Using MySQLI
if($stmt = $connection->query("SHOW DATABASES")){
  echo "No of records : ".$stmt->num_rows."<br>";
  while ($row = $stmt->fetch_assoc()) {
	echo $row['Database']."<br>";
  }
}else{
echo $connection->error;
}
By using mysql_db_list() function we can get the result set and by using a pointer to this result set we can get the list of all the database. With this and using the code below we can list all the databases hosted on the mysql server. Here is the code, ensure that connection is available to the server.
<?Php
$list_of_dbs = mysql_list_dbs();
$i = 0;
$total = mysql_num_rows($list_of_dbs);
while ($i < $total) {
echo mysql_db_name($list_of_dbs, $i) . "<br>";
$i++;}
?>

PHP MySQL functions SHOW Tables

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com

13-10-2023

Please help me.
php syntax to SHOW DATABASES in php. I'm using Linux




SQL Video Tutorials










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer