Line 469: From: $res = $this->connection->query($q); To: $res = $this->connection->query($q, MYSQLI_USE_RESULT); You will be able to store MUCH MUCH MUCH more before runing out of memory.