PHP and PDO class question

后端 未结 3 474
温柔的废话
温柔的废话 2020-12-18 07:13

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:22

    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.

提交回复
热议问题