MySQL databases store data in tables.
For storage of data in the database, it is necessary that it contains at least one created MySQL table.
To show the list of tables in a MySQL database, you can use the following SQL query: SHOW TABLES FROM $dbname;
This function retrieves a list of table names from a MySQL database. The SQL query to get all table names in the current database is: SHOW TABLES;
<?php
$dbhost = "localhost";
$dbuser = "yourusername";
$dbpass = "yourpassword";
$dbname = "yourdatabase";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SHOW TABLES";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output the names of the tables
echo "List of tables in the database:<br>";
while($row = $result->fetch_array()) {
echo $row[0] . "<br>";
}
} else {
echo "No tables found in the database.";
}
$conn->close();
?>