How can PHP loops be optimized when retrieving single row results from a database query?

When retrieving single row results from a database query in PHP, you can optimize loops by using the `fetch()` method instead of `fetchAll()` to fetch only one row at a time. This can help improve performance and reduce memory usage, especially when dealing with large result sets.

// Assuming $stmt is a prepared statement object
$stmt->execute();

// Fetching single row at a time
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    // Process the row data here
}