开发者

Is there a way for a mysqli connection to stay open across files and functions (LAMP)?

开发者 https://www.devze.com 2023-01-27 11:15 出处:网络
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.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消