cgm225 Posted May 23, 2008 Share Posted May 23, 2008 Do I need to close my mysqli object? I am hearing different things, and this article says I need it... Note that open connections (and similar resources) are automatically destroyed at the end of script execution. However, you should still close or free all connections, result sets and statement handles as soon as they are no longer required. This will help return resources to PHP and MySQL faster. What are the communities thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/ Share on other sites More sharing options...
jonsjava Posted May 23, 2008 Share Posted May 23, 2008 My answer is that I'm a bad programmer for not closing it, but I've seen no loss for not doing so. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548242 Share on other sites More sharing options...
.josh Posted May 23, 2008 Share Posted May 23, 2008 Think your quote pretty much says it all... it's not necessary but it's more efficient. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548245 Share on other sites More sharing options...
cgm225 Posted May 23, 2008 Author Share Posted May 23, 2008 Well, what do you do? Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548249 Share on other sites More sharing options...
gluck Posted May 23, 2008 Share Posted May 23, 2008 Ideally you should but not many of us do it. Guess thats why we are coding in php not Java. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548251 Share on other sites More sharing options...
bilis_money Posted May 23, 2008 Share Posted May 23, 2008 close it so the server don't suffer. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548252 Share on other sites More sharing options...
.josh Posted May 23, 2008 Share Posted May 23, 2008 If I do anything officially official I usually cross all my t's and dot all my i's, but I have hundreds of little script projects/messing arounds/hobbies that I don't really bother with "formal" things on. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548255 Share on other sites More sharing options...
Barand Posted May 23, 2008 Share Posted May 23, 2008 The close connection is probably going to be one of the last things your script does, so as it's going to happen anyway I don't usually close it myself. However, if I have several queries and large result set early in the script then I will free the results once it's finished with. If it's only finished with at the end of the script then again, I don't bother. Quote Link to comment https://forums.phpfreaks.com/topic/106962-do-i-need-mysqli-close/#findComment-548350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.