What resources are available for troubleshooting MySQL result resource errors in PHP?

When encountering MySQL result resource errors in PHP, it is often due to improperly handling the result resource returned by a MySQL query. To troubleshoot this issue, make sure to properly free the result resource after fetching the data to avoid memory leaks. Additionally, check for any errors in the query execution that may be causing the result resource to be empty or invalid.

// Perform a MySQL query
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Check for errors in query execution
if(!$result) {
    die("Error in query: " . mysqli_error($connection));
}

// Fetch data from result resource
while($row = mysqli_fetch_assoc($result)) {
    // Process data
}

// Free the result resource
mysqli_free_result($result);