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.
Nope, unless you're sure you've finished communicating with the database for the script run. Even then, you don't need to close it explicitly at all as PHP does that automatically after your script finishes executing, unless you're using mysql_pconnect()
to connect to your database.
even though php does it automatically I can tell as much as if we didnt do it on our site, our db server would reach max_connections really really fast. So its very good practice.
Actually I would structure code like this
open conn make all queries close con
rest of the code
Because then slow devices wont make your connections hang.