PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
WaldoMonster
Forum Contributor
Posts: 225 Joined: Mon Apr 19, 2004 6:19 pm
Contact:
Post
by WaldoMonster » Sat Sep 01, 2007 7:13 am
After connecting to a database with mysqli_connect() is mysqli_close() needed or will it be automatically closed on the end of a script?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Sep 01, 2007 7:14 am
The resource will be collected when it becomes unreachable by the script (that includes the end of the script). The connection will be closed then.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 01, 2007 9:21 am
Although closing it yourself can free up resources earlier allowing other operations to start earlier.
WaldoMonster
Forum Contributor
Posts: 225 Joined: Mon Apr 19, 2004 6:19 pm
Contact:
Post
by WaldoMonster » Sat Sep 01, 2007 10:11 am
This means that something like this makes no sense:
Code: Select all
if (isset($db)) mysqli_close($db);
exit();
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Sep 01, 2007 10:15 am
But it doesn't hurt either.