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

When working with MySQL result resources in PHP, 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 after fetching the data to release the memory used by the result set.

// Execute a query
$query = "SELECT * FROM users";
$result = mysqli_query($connection, $query);

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

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