PHP and PDO class question

后端 未结 3 1130
粉色の甜心
粉色の甜心 2020-12-18 06:53

I am very new to OOP styled PHP, and I am trying to implement PDO as well. I found this nice little class online which handles the database connection, however I have no ide

3条回答
  •  时光取名叫无心
    2020-12-18 07:16

    You should use Dependency Injection:

    $steve = new Person($db_handle);
    

    And yes, using the syntax you're hoping to avoid is the way to do it. You can always assign the class variable to a local method one by saying $dbh = $this->db_handle; which I believe is marginally faster.

提交回复
热议问题