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

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com

    13-10-2023

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

    Post your comments , suggestion , error , requirements etc here





    SQL Video Tutorials










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