Home >Database >Mysql Tutorial >Why Am I Getting a 'mysql_fetch_array(): supplied argument is not a valid MySQL result' Error?

Why Am I Getting a 'mysql_fetch_array(): supplied argument is not a valid MySQL result' Error?

Barbara Streisand
Barbara StreisandOriginal
2024-12-15 05:47:13135browse

Why Am I Getting a

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]"

This error arises when attempting to retrieve data from a MySQL query using the mysql_fetch_array() function while providing an invalid result resource.

In your specific case, the issue may stem from a faulty query. After executing your query with the $connector->query() method, check for any errors using mysql_error().

If your query is valid, another possibility to consider is a problem with your DbConnector class, particularly the fetchArray() function. Ensure it is correctly defined as follows:

function fetchArray($result) {
    return mysql_fetch_array($result);
}

To enhance error handling, consider modifying the query() method in your DbConnector class to throw an exception when an invalid query is encountered:

function query($query) {
    $this->theQuery = $query;
    $queryId = mysql_query($query, $this->link);
    if (!$queryId) {
        throw new Exception(mysql_error() . ".  Query was:\n\n" . $query . "\n\nError number: " . mysql_errno());
    }
    return $queryId;
}

The above is the detailed content of Why Am I Getting a 'mysql_fetch_array(): supplied argument is not a valid MySQL result' Error?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn