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命令时,当然需要用到这个变量啊。