RE: Close MySQL Result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2010-01-20 at 13:24 -0800, Daevid Vincent wrote:

> http://www.php.net/manual/en/function.mysql-free-result.php
> 
> mysql_free_result($myresult); 
> 
> NOTE: mysql_free_result() only needs to be called if you are concerned
> about how much memory is being used for queries that return large result
> sets. All associated result memory is automatically freed at the end of the
> script's execution. 
> 
> http://us2.php.net/manual/en/function.unset.php
> 
> unset($Row);
> 
> > -----Original Message-----
> > From: Slack-Moehrle [mailto:mailinglists@xxxxxxxxxxxxxxx] 
> > Sent: Wednesday, January 20, 2010 1:21 PM
> > To: php-general@xxxxxxxxxxxxx
> > Subject:  Close MySQL Result
> > 
> > I think I am a dork.
> > 
> > How do I close a MySQL result set to free memory?
> > 
> > Given something like this:
> > 
> > $gsql = "Select * from resources where queryName = 'Production';";
> > 
> > $myresult = mysql_query($gsql) or die('Cannot execute Query: 
> > ' . mysql_error());
> > 
> > $Row = mysql_fetch_assoc($myresult);
> > 	
> > if ($Row == true) { $_SESSION['PRODUCTION'] = $Row['queryValue']; }
> > else { $_SESSION['PRODUCTION'] = "TRUE"; }
> > 
> > How do I free up $myresult and $Row?
> > 
> > -ML
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> 
> 


And you can unset() $row if you want to free memory used by that
variable, although it should be noted that once unset, it's up to PHP's
garbage collection to free the memory, but using unset() on the variable
tells PHP that it can free it if necessary.

If you're that worried about memory as well, try to optimise your
queries a little bit. For example, instead of retrieving all the results
in a table and using PHP to output only what you need, use the WHERE and
LIMIT clauses in MySQL to narrow down the results to only those that you
actually need.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux