What are best practices for handling MySQL result resources in PHP when querying a database?

When querying a MySQL database in PHP, it is important to properly handle the result resources returned by the query to avoid memory leaks and improve performance. To do this, you should always free the result resources using the mysqli_free_result() function after you have finished working with the results.

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

// Process the results

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