We should free the mysql results using mysqli_free_result respectively or else this will consume your server RAM resource.
This is demonstrated as below
<?php
$link = mysqli_connect('Hostname','Username','Password','Database');
echo '<br/>Memory Usage Before Query = '.memory_get_usage(false); $resultResource = mysqli_query($link, 'SELECT * FROM test');
echo '<br/>Memory Usage after Query = '.memory_get_usage(false); $result = array();
while ($result[] = mysqli_fetch_assoc($resultResource)) {}
echo '<br/><br/>Memory Usage Before Free Result = '.memory_get_usage(false); mysqli_free_result($resultResource);
echo '<br/>Memory Usage After Free Result = '.memory_get_usage(false); ?>
Output below.
Memory Usage Before Query = 449464
Memory Usage after Query = 466528
Memory Usage Before Free Result = 474208
Memory Usage After Free Result = 457336
So, One can observer there is memory usage after the query is executed. The results are returned by DB server to the web server instantaniously once the query execution is over. The results present on web server are then processed for fetching from the resource link on web server.
Also this is observed that there is lesser memory usage after using mysqli_free_result because the resources stored on web server for respective query are freed by providing respective resource link.