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++;}
?>
13-10-2023 | |
Please help me. php syntax to SHOW DATABASES in php. I'm using Linux |