class test{ protected $pdo; function delete($sql){ $this->exec($sql); } function exec($sql){ echo $this->pdo->exec($sql); }}$a=new test;$a->delete('ver');
See a source code is written in this way. (I omitted a part)
Why is $this->pdo->exec ($sql); Rather than $this->exec ($sql);
What's the effect of adding this PDO?
Reply content:
class test{ protected $pdo; function delete($sql){ $this->exec($sql); } function exec($sql){ echo $this->pdo->exec($sql); }}$a=new test;$a->delete('ver');
See a source code is written in this way. (I omitted a part)
Why is $this->pdo->exec ($sql); Rather than $this->exec ($sql);
What's the effect of adding this PDO?
protected $pdo; The connection to the data is represented. When you need to execute a SQL command, of course you need to use this variable AH.
__construct is estimated to have $this->pdo = new PDO ();
$this->pdo is actually pointing to the PDO class.
$this is just the current class
The above your error message is that your $sql this parameter is not transmitted
Because you didn't initialize PDO.
public function __construct($pdo){ $this->pdo = $pdo;}