What are some best practices for handling MySQL result resources in PHP scripts?

When working with MySQL result resources in PHP scripts, it is important to properly handle and free up the resources to prevent memory leaks and improve performance. One best practice is to always free the result resource using the mysqli_free_result() function after you have finished using it. This ensures that the memory used by the result set is released back to the system.

// Execute a query and store the result in a variable
$result = mysqli_query($conn, "SELECT * FROM users");

// Process the result set
while ($row = mysqli_fetch_assoc($result)) {
    // Do something with the data
}

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