title: How can I save the contents of a mysqli_result object?
body: <p>Hey guys Im currently trying to debug some code for a mysqli encapsulation class. Ive run into a problem described <a href="http://www.php.net/manual/en/class.mysqli-result.php#100530" rel="nofollow">here</a> have tried a few solutions with this being the latest iteration and (doesn't seem to work):</p>
  
  <pre><code>$this-&gt;result = new stdClass();
  foreach($res = $this-&gt;conn-&gt;query($sql) as $key =&gt; $value) {
      $this-&gt;result-&gt;$key = $value;
  }
  </code></pre>
  
  <p>If anyone knows a way to store the results somehow or create a system with pointers and $result->free_result(); bring called at sometime it would be much appreciated. Im a little stumped and very short for time.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT as of right now my original implementation seems to be working not sure if this will hold true through testing. Currently I have a custom $this->query() function calling mysqli->query and storing the results in $this->result, however under some circumstances it seems $this->result becomes unset. Going to keep testing/debugging what I have and see if it happens again. Thanks to those who answered :)</p>
  
  <p>EDIT 2 Through a fair bit of trial and error Ive traced the issue I was having back to a SQL query behaving oddly. It seems its not possible to store the resulting object from mysqli::query() without issue(?).</p>