title: Zend_Db: fetchAll() or query()/fetch() for a huge number of records
body: <p>Assuming I have</p>
  
  <pre><code>$db is an instance of Zend_Db_Adapter_Abstract and
  $sql = 'SELECT blah blah FROM table' will return a huge number of records.
  </code></pre>
  
  <p>There are two code fragments to process the returned data as follows.</p>
  
  <pre><code>// Code fragment 1 (let's call it C1).
  $results = $db-&gt;fetchAll($sql);
  foreach ($results as $row) {
      // Process $row
  }
  
  // Code fragment 2 (let's call it C2).
  $stmt = $db-&gt;query($sql);
  while ($row = $stmt-&gt;fetch()) {
      // Process $row
  }
  </code></pre>
  
  <p>My understanding is that C1 will load all returned data to $results. So, a huge data is loaded to PHP memory. Below are my questions.</p>
  
  <ol>
  <li>Does C2 load all data to PHP memory or does it process one by one like prepare/execute?</li>
  <li>Assuming there is no other option, is C1 or C2 a better option?</li>
  </ol>
  
  <p>Thanks!</p>