Skip to content
PHP Logo

What could be causing a PHP script to continue running even when there is no data in the database?

The issue could be caused by a logic error in the PHP script that does not properly handle the case when there is no data in the database. To solve this, you should check if there is data returned from the database query before proceeding with any further processing in the script.

php
// Check if there is data returned from the database query
if($result = $mysqli->query("SELECT * FROM table_name")) {
    if($result->num_rows > 0) {
        // Process the data
        while($row = $result->fetch_assoc()) {
            // Code to process each row
        }
    } else {
        // No data in the database
        echo "No data found in the database";
    }
    $result->free();
} else {
    // Error with the database query
    echo "Error: " . $mysqli->error;
}