mysqli_close() needed?

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

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

mysqli_close() needed?

Post by WaldoMonster »

After connecting to a database with mysqli_connect() is mysqli_close() needed or will it be automatically closed on the end of a script?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Although closing it yourself can free up resources earlier allowing other operations to start earlier.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

This means that something like this makes no sense:

Code: Select all

if (isset($db)) mysqli_close($db);
exit();
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But it doesn't hurt either.
Post Reply