What is the best method for global var in function/class? PHP

后端 未结 1 1439

my problem \"is too many connection to MySQL\" because i had created a new object for each function that had needed it.

What is the best solution for this operation? The

相关标签:
1条回答
  • 2021-01-26 09:42

    I'd say both are bad, pass the $db object in as an argument to the functions:

    function test($db) {
        $db->prepare(...);
    }
    
    0 讨论(0)
提交回复
热议问题