PHP Function Accessing Database Connection

前端 未结 5 500
走了就别回头了
走了就别回头了 2021-01-14 09:15

How do I allow a function to access a database connection without using GLOBAL?

config.php

 DEFINE (\'DB_HOSTNAME\', \'hostname\');
 DEFINE (\'DB_DAT         


        
5条回答
  •  时光说笑
    2021-01-14 10:00

    There are more ways. You could use classic procedural style:

    function something($dbc)
    

    or anonymous function (if you use PHP5.3):

    $fn = function() using ($dbc)
    

提交回复
热议问题