Replacing mysql_list_dbs() with SHOW DATABASES

The removed mysql_list_dbs() API is unnecessary in modern PHP. MySQL provides the SHOW DATABASES statement, which can be executed through PDO, MySQLi, the command-line client or GUI tools.

SHOW DATABASES

SHOW DATABASES;

The databases visible in the result depend on the current account's privileges and server configuration.

PDO example

<?php
$stmt = $dbo->query('SHOW DATABASES');
foreach ($stmt as $row) {
    echo htmlspecialchars($row[0]) . '<br>';
}
?>

MySQLi example

<?php
$result = $connection->query('SHOW DATABASES');
while ($row = $result->fetch_assoc()) {
    echo htmlspecialchars($row['Database']) . '<br>';
}
?>

Historical mysql_list_dbs()

<?php
// Historical only: mysql_list_dbs() and mysql_db_name() were removed with mysql_*.
$list = mysql_list_dbs();
?>

To create a database, see CREATE DATABASE from PHP. For table-level discovery, continue with SHOW TABLES.

Create database · SHOW TABLES · Database tutorial · PHP/MySQL overview · MySQL front-end tools

← All PHP & MySQL topics




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










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