SHOW TABLES
Using this we can develop a PHP script to display all tables.
<?Php
require "config.php"; // Database Connection
$result = $dbo->query("SHOW TABLES");
while ($row = $result->fetch(PDO::FETCH_NUM)) {
echo $row[0]."<br>";
}
?>
SHOW TABLES in PDO
Above query will return all the tables of the database pdoSHOW 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.
<?Php
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>";
}
}else{
echo $connection->error;
}
<?Php
$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>";
$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.
| Vicente Carlos | 20-05-2012 |
| I1m loving your site! Very usefull. Thanks | |
| ram | 02-11-2012 |
| this website is very useful. thank you | |
| Deepak | 22-04-2015 |
| Helpful website. But Please also include a demo of code if possible. Thank you for helping coders. | |