Reputation: 1399
I'm always calling mysqli_close()
before issuing die()
command.
It's tedious and sometimes forgettable, but I want to make sure if the die
command closes all mysql connections or does it still leave it opened?
I can't check via PHP since the script stops after the die()
command.
Upvotes: 2
Views: 1151
Reputation: 33457
When script execution ends, all non persistent resources are closed.
In short, it is entirely safe to just bail out of execution. PHP will handle closing everything for you. (Except, once again, for persistent connections, though those need somewhere to stay open, so if you're just the plain PHP executable without a webserver wrapped around it, those will be closed too.)
Side note: I've never been able to find any official documentation of this, so you probably shouldn't depend on it, but from some testing I did a few weeks ago when a similar question was asked, it seems that resources are closed immediately upon going out of scope. I also only tested with file and mysql connection resources, so it might just be those.
Upvotes: 5