Is there a way for a mysqli connection to stay open across files and functions (LAMP)?
I have an index.php and a functions.php.
The index.php does not make connections to the database but uses functions from functions.php that connect all to the same database.
The functions start with
$mysqli = new mysqli('***', '***', '***', '***');
[...]
$mysqli -> close();
As the app grows there are more and more functions which call one other and I'm thi开发者_StackOverflownking there must be a better method than constantly opening and closing connections.
Have you tried using classes?
Maybe put the MySQL connection statement in the ctor and using a class member to hold the mysqli handle?
精彩评论