basically i'd like to know if it's preferable to establish a database connection before each database que开发者_如何学JAVAry, and then use mysqli_close() immediately after the relevant section, for every spot in the layout where database information has to be pulled - or if it's better to just open the database connection at the start of the file, and then use mysqli_close() near the end of the file.
One connection per request is more efficient. Only if you do many concurrent updates on the same rows is important to commit (close connection) as fast as posible.
it's better to just open the database connection at the start of the file, then get all the data, then use mysqli_close(), and then call a template to start displaying a page.
Use the connection pooling, so it really doesn't matter how often you request a connection in the code. Applications wishing to be scalable should avoid rapidly creating new connections, as they potentially could have noticeable overhead for encryption setup or waiting for a authentication server.
精彩评论