title: Allowed memory size of bytes exhausted on bind_result
body: <p>I've had a dynamic query that is built by union smaller queries. I use union because I need to get data from a few tables in too one big list. The tables have much in common but I still need the data in seperate tables. Therefore I thought this solution seemed to be the best one.
  This have worked good so far but today I added some more queries and now it's broken and it gives me this error:</p>
  
  <p><code>Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 150994936 bytes)</code></p>
  
  <p>The error refers to this function:</p>
  
  <pre><code>function selectResults($stmt){
      $parameters = array();
      $results = array();
  
      $meta = $stmt-&gt;result_metadata();
  
      while ( $field = $meta-&gt;fetch_field() ) {   
       $parameters[] = &amp;$row[$field-&gt;name]; 
      }
  
      //------THIS IS WHERE THE ERROR IS------
      call_user_func_array(array($stmt, 'bind_result'), $parameters);
      //--------------------------------------
  
      while ( $stmt-&gt;fetch() ) {
        $x = array();
        foreach( $row as $key =&gt; $val ) {
           $x[$key] = $val;
        }
        $results[] = $x;
      }
  
      return $results;
  
  }
  </code></pre>
  
  <p>The function is called like this:</p>
  
  <pre><code>$mysqli = new mysqli('localhost', 'username', 'pass', 'db');
  $stmt = $mysqli -&gt; prepare("some query");
  $stmt -&gt; execute();
  $results = selectResults($stmt);
  $stmt -&gt; close();
  $mysqli -&gt; close();
  </code></pre>
  
  <p>The query can be about 1500 words, is that all too much?</p>
  
  <p>Will putting all of the tables into the same one and just having one query solve this?</p>