What potential pitfalls should be avoided when using mysqli_fetch_all in PHP to retrieve data from a database?

When using mysqli_fetch_all in PHP to retrieve data from a database, one potential pitfall to avoid is the possibility of running out of memory if the result set is too large. To prevent this, it's recommended to limit the number of rows fetched at a time or use pagination to retrieve data in smaller chunks. Additionally, be cautious when fetching large datasets and consider optimizing your queries to only fetch the necessary data.

// Example code snippet demonstrating how to limit the number of rows fetched at a time
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

while ($row = mysqli_fetch_array($result)) {
    // Process each row here
}