"php mysql - when is the best time to disconnect from the database?" Code Answer

4

as far as i know, unless you are using persistent connections, your mysql connection will be closed at the end of the page execution.

therefore, you calling disconnect will add nothing and because you do the lazy connection, may cause a second connection to be created if you or another developer makes a mistake and disconnects at the wrong time.

given that, i would just allow my connection to close automatically for me. your pages should be executing quickly, therefore holding the connection for that small amount of time shouldn't cause any problems.

By Bob Dem on June 19 2022

Answers related to “php mysql - when is the best time to disconnect from the database?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.