Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.close? #2

Open
commentatorboy opened this issue Nov 11, 2016 · 2 comments
Open

db.close? #2

commentatorboy opened this issue Nov 11, 2016 · 2 comments

Comments

@commentatorboy
Copy link

Hey thanks for making this. I wanted to ask if you also should make a function that could close the connection?
f.x. here:
http://php.net/manual/en/function.mysql-close.php

@geeShoe
Copy link

geeShoe commented Nov 13, 2016

@commentatorboy

The link you posted above is in reference to mysql_close(), not to be confused with mysqli_close();

In regards to mysql_close();

Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_close()
PDO: Assign the value of NULL to the PDO object

http://php.net/manual/en/mysqli.close.php <- mysqli_close is however not depreciated. Always double check that your looking at the mysqli documentation instead of the depreciated mysql documentation..

To answer your question, you do not have to explicitly close the connection by calling mysqli_close() as the connection will be automatically destroyed when the script has completed execution. If you're developing an app that will be used in a limited resource environment, than it's not a bad idea to explicitly close the connection manually via mysqli_close() as soon as possible to free up resources.

On a side note, mysqli_close() will not close persistent connections.

Hope this helps...

@commentatorboy
Copy link
Author

@geeShoe Ah fair enough. Yeah thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant