Home >Database >Mysql Tutorial >Why Am I Getting the \'mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource\' Error?
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!