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;
}
<?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++;}
?>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
13-10-2023 | |
| Please help me. php syntax to SHOW DATABASES in php. I'm using Linux | |