How can one efficiently check for the existence of a specific table in a MySQL database using PHP?

To efficiently check for the existence of a specific table in a MySQL database using PHP, you can use the "SHOW TABLES LIKE" query to search for the table name. If the query returns a result, it means the table exists in the database.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$table_name = "your_table_name";

// Check if table exists
$result = $conn->query("SHOW TABLES LIKE '$table_name'");
if($result->num_rows > 0) {
    echo "Table $table_name exists in the database.";
} else {
    echo "Table $table_name does not exist in the database.";
}

$conn->close();
?>