首页 > $this->pdo->exec($sql);这是什么意思

$this->pdo->exec($sql);这是什么意思

class test{
      protected $pdo;
    function delete($sql){
        $this->exec($sql);
    }
    function exec($sql){
        echo $this->pdo->exec($sql);
    }
}
$a=new test;
$a->delete('ver');

看到一个源码是这样写的。(我省略了一部分)

为什么是$this->pdo->exec($sql); 而不是$this->exec($sql);
加上这个PDO有什么作用呢?


protected $pdo;代表的就是和数据的连接。当需要执行SQL命令时,当然需要用到这个变量啊。


因为你没有初始化pdo

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

估计 __construct 中 有 $this->pdo = new PDO();之类的
$this->pdo 其实是指向了PDO这个类
$this 只是当前类
上面你的报错信息是说 你的 $sql 这个参数没传

【热门文章】
【热门文章】