I am looking for some guidance on best practice wrt DB operations in a PHP dynamic web site.
To be clear, this web site makes no changes to the data (that happens elsewhere).
It seems to me there are four distinct operations.
- Defining the DB Connection
- Opening the DB Connection
- Selecting data from the DB
- Closing the DB Connection
The question is when (in the flow of building each page) to perform each of them.
It’s not really a question of performance, I’ve tried Open once and Open for every select, there seems to be negligible impact on performance (although I’ve not tried to measure at scale). Rather it’s a question of best practice for future code maintenance.
Thank you.