Reputation: 5141
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?
Upvotes: 2
Views: 103
Reputation: 1096
I've always closed them as soon as I was finished with them. Why leave them open when you don't need them?
Upvotes: 0
Reputation: 2180
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).
Upvotes: 4