Re: no temp var for mysql_fetch_array results
| From: | Justin Patrin | Date: | Wed, 12 May 2004 17:07:00 +0000 |
| Subject: | Re: no temp var for mysql_fetch_array results | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34408@lists.php.net to get a copy of this message | ||
You'd have to ask someone with more internals knowledge for that one... I'm sure it does get GC'd, but I don't know if it happens in-script or at the end. Also, I would assume it is freed when GC'd, but who knows, I might be wrong. It's much safer to free it yourself.
paperCrane <Justin Patrin>
David T-G wrote:
Justin, et al -- ...and then Justin Patrin said... % % David T-G wrote: % % >...and then Justin Patrin said... % >% ... % >% Of course, this leaves the result handle open. It's best to store the % >% result handle and free it with mysql_free_result(). % > % >Makes sense. I actually hadn't thought of that; do I need to do that % >after a typical while(mysql_fetch_array()) or does the exhaustion caused % >by the while loop then close and free for me? % % Nope, it's kept open so that you can use a seek to go back to the % beginning i fyou want to (at least, I'm pretty sure that's what it's % doing). You should always use mysql_free_result on your statement/result % handle. Ahhhhh... Very interesting. One learns something every day :-) % % Of course, you don't *really* need to do this if your script is small as % PHP will free everything when it's done, but it's good coding style and % can keep you from (possibly) running out of memory in larger scripts. Right. And surely someone who so fastidiously fclose()s every fopen()ed file, even if it was opened read-only, would want to tie up any loose db ends in the same way! One last question... If I make a query and run through the results and then make another query, reusing the same result handle, should I have freed the first result before assigning the second? That is, does that handle get closed automatically or orphaned for garbage collection at the end of the script? % % -- % paperCrane <Justin Patrin> Thanks again & HAND :-D