hi,
I also have the same type of questions. I was always under the inpression that in most cases, it is best (performance wise) to open a db connection as late as possible and to close it as soon as possible. So when i have functions that use the database i would open and close the connection within the funciton.
The question i have is that when i call this type of function when a database connection is already open, then when the function is done, it closed the original database connection i already had opened.
ie:
Open DB $db_conn
Call function (opens and closes $db_conn)
** Error since $db_conn is closed by function.
What i have been doing is just creating another new connection for within the function to prevent any previous connections from being closed. But i dont know if creating 2 connections here is so good.😕
Thanks