Right now I open a connection (if one is not already opened) every time I think I will need one. The question is: when I do close it? At the end of each script that uses it? Is there a standard for this sort of thing?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re talking about PDO (your tag): Connections are automatically closed when your script terminates except you’re using persistent connections.
It’s not really necessary to close your database links yourself in normal web application unless you have long-running scripts (that don’t require a continuous database connection).