开发者

When to close a connection in PHP?

开发者 https://www.devze.com 2023-04-10 03:17 出处:网络
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

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?


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).


I've always closed them as soon as I was finished with them. Why leave them open when you don't need them?

0

精彩评论

暂无评论...
验证码 换一张
取 消