![]() |
When to free sql results?
For a lot of my web designs I'll run a bunch of queries on the same page. I usually run the queries before any HTML and retrieve the $row_someRS['someField'] inside the HTML to echo information on the web page. After the end of the HTML I will run <?php
mysql_free_result($someRS); ?> to clean things up. Lately I've been also embedding code like this to populate menu's and run forms: PHP Code:
Thanks for your input. |
You can run them as soon as you are done with them. PHP *should* release the resource at the script termination (should being the keyword) if you don't issue a shutdown. The purpose is to free up memory that you no longer require to be held, so if you use large datasets, free them as soon as you can.
MySQLi with prepared statements are different. You should close the statement as soon as you are finished with them; depending on the usage they can block other commands until they are free. Since you need to move to MySQLi or PDO soon anyways, you may as well get used to issuing free now. |
So if I'm following your post correctly right after the last closing bracket in the sample code I should add the free command. It would look like this:
PHP Code:
PHP Code:
|
No the free result call would go after the loop. You have it after the function, so you've already lost the stack variable used within it (and best I can tell it would then wait for the script shutdown to release).
$run has no conflict here. That is within a function so $run within the scope of get_sub_cats2 has no relationship to $run declared in main or any other function. |
Ok, so release would go here:
PHP Code:
|
Yep that's correct.
|
| All times are GMT +1. The time now is 01:07 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.