Is it necessary to explicitly close a DB connection after executing a query (and other DB operation)?
No, php does that automatically. You could call it "good programming practice" to clean up (aka close the connection) though.
Generally, only close it after you have finished the database for that entire page. Also, depending on the API you are using to handle the database, most ones you should be using now (such as PDO) are implemented via Objects, so the destructor will automatically handle closing it at the end if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With