Skip to content

Instantly share code, notes, and snippets.

View softail's full-sized avatar
🏠
Working from home

Temo softail

🏠
Working from home
View GitHub Profile
@softail
softail / question1.md
Created April 22, 2026 11:34
Coding Exemplar

Answer 1

Fix: Replace fetchAll() + foreach with a while + fetch() loop.
PDO streams one row at a time, keeping memory usage constant regardless of table size.

$stmt = $pdo->prepare('SELECT * FROM largeTable');
$stmt->execute();

while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
 // manipulate the data here