What is the best way to check if entries exist in a MySQL database table using PHP?

To check if entries exist in a MySQL database table using PHP, you can execute a SELECT query and then check the number of rows returned. If the number of rows is greater than 0, it means entries exist in the table.

<?php

// Establish a connection to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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

// Execute SELECT query to check if entries exist
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

// Check if entries exist
if ($result->num_rows > 0) {
    echo "Entries exist in the table.";
} else {
    echo "No entries found in the table.";
}

// Close the connection
$conn->close();

?>