title: Looping through a large number of database rows in Yii2
body: <p>I'm using Yii2 and my database server is MySQL. I need to scan every row of a whole db table searching for occurrences of some text.</p>
  
  <p>This is what I want but because of the large number of records, I'm not sure if I do it like this the server won't run out of memory or the MySQL server wont go away:</p>
  
  <pre><code>$rows = Posts::find()-&gt;select('content')-&gt;all();
  foreach($rows as $post) {
      // do some regex on $post['content']. no need to save it back to the table.
  }
  </code></pre>
  
  <p>It's a live server with a large database. I must do it on the fly, can't take down the server for back up and restore!</p>
  
  <p>Would this work? Is there any better way to do this? </p>