Possible Duplicate:
Do I need to use mysql_close(connection)?
Is it best to close a MySQL connection at the end of a script, or store all MySQL queries for that page in arrays at the beginning, close the connection, then output the data?
On one hand, closing it at the end seems like it would cause problems eventually if pages are constantly refreshed before the page has time to load. On the other, grabbing everything at the start would place everything into memory. If they didn’t wait for the page to load completely, all of it didn’t need to be loaded, so it wasted memory.
Sure, the memory gets freed. But for a site that get’s a lot of hits, and a lot of constant F5’s, which is the better way?
Usually you don’t have to close connections, they are handled internally.
Also doing all your queries, and then closing the connection could cause problems when you try and fetch result sets.