Should we use mysqli_close() and mysqli_free_result() whenever we use MySQL in a page?
If yes, when and where? What if the script is small?
Does this make any sense?:
mysqli_free_result($dbc);
mysqli_close($dbc);
exit();
Thanks
Should we use mysqli_close() and mysqli_free_result() whenever we use MySQL in a page?
If yes, when and where? What if the script is small?
Does this make any sense?:
mysqli_free_result($dbc);
mysqli_close($dbc);
exit();
Thanks
Those statements are rather pointless in that example since the exit() will run them anyway.
The only time you need them is when you are going to have the script do some other processing between finishing with the database and exiting.
In this example, yes, there is no real point to it.
If you were going to pull several large result sets in a single page execution, you might want to use free_result.
close would only really come into play if you’re going to be either running the page for a long time (thus holding a connection that may be used by another cllient, in the case of connection-limited databases) or as felgall pointed to, if you’re going to be doing processing on things outside of the database that may take long enough for garbage collection to become an issue for other scripts.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.