Use global variables in a class

前端 未结 4 1720
日久生厌
日久生厌 2020-11-22 13:36

I\'m trying to create a pagination class and use a variable from outside the class.

But it\'s giving me the fatal error \"Call to a member function query() on a non-

4条回答
  •  醉酒成梦
    2020-11-22 14:07

    you could add the db-connection ($db) to the call of the get_records method:

    Here are only the relevant lines of code:

    First file:

    $records = $pagination->get_records("SELECT * FROM `table`", $db);
    

    Second file:

    public function get_records($q, $db) {
    

提交回复
热议问题