W3docs

mysql_fetch_array() expects parameter 1 to be resource

It looks like you are trying to use a function from the MySQL extension in PHP, but you are getting an error saying that the first parameter should be a resource.

It looks like you are trying to use a function from the MySQL extension in PHP, but you are getting an error saying that the first parameter should be a resource.

This error is usually caused by one of the following issues:

  1. You are trying to use the function on a variable that is not a valid MySQL result resource. Make sure that you have a valid MySQL result resource before calling any of these functions.
  2. You are using an outdated version of PHP. The MySQL extension has been deprecated as of PHP 7.0 and has been removed as of PHP 7.4. If you are using a version of PHP later than 7.0, you should use either the MySQLi extension or PDO instead.
  3. You are passing an incorrect variable type (e.g., null, false, or the connection resource instead of the result resource) to the function. This often happens when a query fails and returns false, but the failure isn't checked before fetching.

To fix the problem, you should check your code and make sure that you are using a valid MySQL result resource and that you are using the correct function for the version of PHP that you are using.

Before (Error):

// Fails if query returns false or $result is not a resource
$result = mysql_query("SELECT * FROM users");
$row = mysql_fetch_array($result); // Warning: expects parameter 1 to be resource

After (Fixed with MySQLi & Error Handling):

$conn = mysqli_connect("localhost", "username", "password", "database");
$result = mysqli_query($conn, "SELECT * FROM users");

if ($result) {
    $row = mysqli_fetch_array($result);
} else {
    echo "Query failed: " . mysqli_error($conn);
}

Migration to PDO:

$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');
$stmt = $pdo->query('SELECT * FROM users');
$row = $stmt->fetch(PDO::FETCH_ASSOC);