The connection closes when the thread that opened it finishes, ie when your script finishes (generally). If you are not going to run another query in the script then close it, if you are running additional queries then don't: the overhead of openning a connection several times from the same script outweighs the overhead of keeping one open.