PHP MySQL Functions to list table names in a databases

We can list tables present in a database by using this query
Using this we can develop a PHP script to display all tables.
require "config.php"; // Database Connection

$result = $dbo->query("SHOW TABLES");

while ($row = $result->fetch(PDO::FETCH_NUM)) {
echo $row[0]."<br>";

Show tables of a database

We can display tables of a database by changing the above query.
Above query will return all the tables of the database pdo
Similarly if we want to list all the tables starting with char t then we can use LIKE command. Here is the query.
SHOW TABLES from pdo LIKE 't%'
Above query can be placed inside the PHP code (shown above ) to display matching tables. For easy understanding here again the php code.
require "config.php"; // Database Connection

$result = $dbo->query("SHOW TABLES from pdo LIKE 't%'");

while ($row = $result->fetch(PDO::FETCH_NUM)) {
echo $row[0]."<br>";
Using MySQLI
if($stmt = $connection->query("SHOW TABLES")){
  echo "No of records : ".$stmt->num_rows."<br>";
  while ($row = $stmt->fetch_array()) {
echo $row[0]."<br>";
echo $connection->error;


We can display a list of tables present in a database by using mysql_list_tables() function. Connection has to be established before call of this function. The result pointer returned by this function is used by mysql_tablename() function to display the name of the tables.
$list = mysql_list_tables ("sql_tutorial");
$i = 0;
while ($i < mysql_num_rows ($list)) {
$tb_names[$i] = mysql_tablename ($list, $i);
echo $tb_names[$i] . "<BR>";

PHP MySQL functions SHOW Databases

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net
    Vicente Carlos


    I1m loving your site! Very usefull. Thanks


    this website is very useful. thank you


    Helpful website. But Please also include a demo of code if possible. Thank you for helping coders.

    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 All rights reserved worldwide Privacy Policy Disclaimer