title: PHP PDO ALlowed Memory Exhausted when allocating 64 bytes
body: <p>I have 2 scripts which are technically the same, but one works, and the other produces the error:</p>
  
  <pre><code>( ! ) Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes) in C:\wamp\www\SOTag\SOTag.php on line 29
  </code></pre>
  
  <p>Line 29 being:</p>
  
  <pre><code>$rows[] = $r;
  </code></pre>
  
  <p><strong>This is the code that works:</strong></p>
  
  <pre><code>$this-&gt;connect_db();
  $statement = $this-&gt;db_connection-&gt;prepare("SELECT * FROM tags WHERE tag LIKE :keywords");
  $statement-&gt;bindParam(':keywords', $keywords, PDO::PARAM_INT);
  $statement-&gt;execute(compact('keywords'));
  
  $rows = array();
  while($r = $statement-&gt;fetch(PDO::FETCH_ASSOC)) {
      $rows[] = $r;
  }
  return json_encode($rows);
  </code></pre>
  
  <p><strong>And this is what I need to do (as I need to check for results) but it fails:</strong></p>
  
  <pre><code>$this-&gt;connect_db();
  $statement = $this-&gt;db_connection-&gt;prepare("SELECT * FROM tags WHERE tag LIKE :keywords");
  $statement-&gt;bindParam(':keywords', $keywords, PDO::PARAM_INT);
  $statement-&gt;execute(compact('keywords'));
  $result = $statement-&gt;fetch(PDO::FETCH_ASSOC);
  
  $rows = array();
  while($r = $result) {
      $rows[] = $r;
  }
  return json_encode($rows);
  </code></pre>