What are the potential pitfalls of using mysqli_fetch_assoc() when retrieving data from a MySQL database in PHP?

Potential pitfalls of using mysqli_fetch_assoc() include the risk of memory issues when dealing with large result sets, as all data is loaded into memory at once. To mitigate this, you can fetch data row by row using a while loop to avoid loading all data into memory at once.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query the database
$result = mysqli_query($connection, "SELECT * FROM table");

// Fetch data row by row
while($row = mysqli_fetch_assoc($result)) {
    // Process each row as needed
    echo $row['column_name'] . "<br>";
}

// Close the connection
mysqli_close($connection);