Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is a good idea to start unsetting variables if you know they use a lot of memory, like huge images, or big SQL query results, but only if you know for sure the info isn't needed anymore, and if your PHP complains about not having enough memory. Or your webserver. Freeing tiny parts of memory in the middle of a block of still used memory is useless. It won't be reused. And reordering the memory would eat performance. PHP is pretty optimized in dealing with variables.</p> <p>Unsetting a variable will free it's memory if there is no other reference pointing to the value. This is true for an array as well: All array keys are references to their values, and if they are the only one, unsetting the array itself will unset all stored values inside.</p> <p>You should know that query results are stored entirely in memory. You cannot access it directly, but there are functions like <a href="http://php.net/manual/en/mysqli-result.data-seek.php" rel="nofollow">mysqli_result::data_seek()</a> that will let you point to the entry you want to read, and the next call to <code>mysqli_result::fetch_assoc()</code> will get it.</p> <p>If you are really copying the result to an array, you are at least doubling your memory consumption until you delete the query result (either explicitly with a call to <code>mysqli_result::free()</code>, or by unsetting the result object).</p> <p>You could however also create a wrapper around the mysqli_result that implements the <a href="http://de3.php.net/manual/en/class.arrayaccess.php" rel="nofollow">ArrayAccess</a> interface (and probably also <a href="http://de3.php.net/manual/en/class.iterator.php" rel="nofollow">Iterator</a> and <a href="http://de3.php.net/manual/en/class.countable.php" rel="nofollow">Countable</a>). This IS your array - without copying. An access to a random value would first call <code>seek()</code>, then <code>fetch_assoc()</code>, and return the value. </p> <p>You then have the freedom to make use of all the SPL classes. Want to filter the result when running over it with foreach? Implement your own FilterIterator, put your result wrapper inside, and there you go.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload