How can a PHP developer generate an error message when a record does not exist in the database?

When a PHP developer wants to generate an error message when a record does not exist in the database, they can use a conditional check to verify if the query returned any results. If no results are returned, an error message can be displayed to inform the user that the record does not exist.

// Assuming $conn is the database connection object and $id is the record ID being searched for
$query = "SELECT * FROM table_name WHERE id = $id";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) == 0) {
    echo "Error: Record does not exist in the database.";
} else {
    // Process the record if it exists
}