Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The mysql_ Extension Is Obsolete: Why You See "Resource, Boolean Given" Errors

The error message Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given is a classic symptom of code running on a modern PHP environment that hasn't been updated since the early days of web development. It does not indicate a bug in your logic or a database connectivity issue; it signals that you are relying on an extension that has been deprecated and ultimately removed from the core PHP distribution.

When you execute mysql_query(), the function returns a resource (a link identifier) if the query succeeds, or a boolean false if it fails. In older versions of PHP (5.x), this behavior was consistent. However, starting with PHP 7.0.0, the entire mysql_* extension was removed. Before that removal, in PHP 5.5.0+, these functions were marked as deprecated and emitted deprecation warnings. If you are running PHP 5.6 or higher, you will see this warning immediately upon attempting to fetch data from a failed query.

The core issue lies in the fact that your script assumes the database connection is active without verifying it. In your specific example, you run $result1 = mysql_query($query);. If the server cannot connect to the database, or if the table residential does not exist, mysql_query() returns false. The subsequent check if (mysql_num_rows($result1) > 10) is where things go wrong. While mysql_num_rows() technically handles boolean inputs in some contexts by returning 0 for false, the logic inside your conditional block assumes success.

More critically, when you eventually reach $result2 = mysql_query($myQuery); and attempt to iterate with while ($line = mysql_fetch_array($result2, MYSQL_BOTH)), if $myQuery failed or returned false, passing that boolean directly into mysql_fetch_array() triggers the fatal warning. The function signature expects a resource, but receives a boolean because the previous step did not validate the result.

Modernizing to mysqli or PDO

The immediate fix is to migrate away from mysql_* functions entirely. There are two standard paths forward: the Object-Oriented mysqli extension or PDO. Given that you are dealing with raw SQL strings in your current code, switching to mysqli requires minimal syntax changes, whereas PDO offers a cleaner separation of concerns but requires more boilerplate for simple scripts.

Here is how you can refactor your specific logic using mysqli. First, establish a connection and use prepared statements or at least verify the result of every query:

// Establish connection (using mysqli)
$connection = new mysqli($host, $user, $password, $database);

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

// Execute the initial check
$query = "SELECT ListNumber FROM residential";
$result1 = $connection->query($query);

if (!$result1) {
    // Handle error immediately if the query fails
    echo "Query failed: " . $connection->error;
} else {
    $count = $result1->num_rows;
    
    if ($count > 10) {
        $difference = $count - 10;
        
        // Construct the second query
        // Note: Be cautious with string interpolation in LIMIT. 
        // Consider using prepared statements for dynamic parts if security is a concern,
        // though LIMIT arguments are typically passed as strings.
        $myQuery = "SELECT * FROM `residential` ORDER BY `id` LIMIT 10," . (int)$difference;
        
        $result2 = $connection->query($myQuery);
        
        if ($result2) {
            while ($line = $result2->fetch_assoc()) {
                // Process your data here
            }
        } else {
            echo "Second query failed: " . $connection->error;
        }
    }
}

Why This Matters Beyond the Warning

The warning you encountered is just the tip of the iceberg. The mysql_* extension lacks modern features like prepared statements (for preventing SQL injection), transaction support, and multiple database connections. Furthermore, it does not support advanced data type handling or stored procedures effectively.

By switching to mysqli or PDO, you gain access to error modes that allow exceptions (mysqli_report(MYSQLI_REPORT_ERROR)) rather than relying on warnings. This changes the debugging workflow from parsing error logs to using standard try-catch blocks in your application code.

If you are maintaining a legacy project, the migration path is non-negotiable for any deployment environment running PHP 7 or higher. Many hosting providers have already disabled the mysql extension entirely. Continuing to use it means your site will fail silently or crash whenever a query encounters an error, making debugging nearly impossible without seeing the specific "resource, boolean given" message.

For developers looking to modernize their stack further, frameworks like Laravel abstract these complexities away. If you are starting a new project or refactoring a large codebase, consider leveraging the ecosystem tools available at https://laravelcompany.com for guidance on integrating robust database handling patterns that avoid these legacy pitfalls entirely.

Our network