Home  >  Article  >  Database  >  Why Am I Getting the \"mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource\" Error?

Why Am I Getting the \"mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource\" Error?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-01 16:15:02263browse

Why Am I Getting the

Troubleshooting mysql_fetch_assoc() Error: Supplied Argument Not a Valid MySQL Result

The error "mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource" arises when trying to access data from a MySQL query using the mysql_fetch_assoc() function but the supplied argument is not a valid result resource.

Possible Cause and Solution

One common cause of this error is overwriting the $result variable, which holds the MySQL result resource. Check the code within the loop to ensure that the $result variable is not being unintentionally overwritten.

In the example provided in the question:

<code class="php">$query = "SELECT UniqueID FROM configuration";
$result = mysql_query($query) or die(mysql_error());;

while ($row = mysql_fetch_assoc($result)) {}</code>

If there is any code within the loop that inadvertently overwrites the $result variable, it would result in the above error. To rectify this, make sure to preserve the $result variable throughout the loop.

The above is the detailed content of Why Am I Getting the \"mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource\" 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