Undefined variable: pdo, call to a member function prepare() on null

后端 未结 1 1882
轮回少年
轮回少年 2020-12-11 11:41

I was following a video and double checking all code and everything seems to be the same yet I get these errors.

Errors:

Notice: Undefin

1条回答
  •  -上瘾入骨i
    2020-12-11 12:10

    As stated in comments, in OOP, you need to use $this->pdo passing the object's property for it, instead of the variable $query = $pdo-> since you've construct'ed it in:

    public function __construct($pdo)
    {
        $this->pdo = $pdo;
        ^^^^^^^^^^
    }
    

    I.e.:

    $query = $this->pdo->prepare
    

    0 讨论(0)
提交回复
热议问题