- 把 php公用方法库中的 数据库操作函数, 重写到 Db类中。
class Db{
public $dsn;
public $user;
public $password;
public $pdo;
// 类里面的方法,不需要顺序。
public function __construct($dsn,$user,$password){
$this->dsn = $dsn;
$this->user = $user;
$this->password = $password;
$this->connect();
}
public function connect(){
$this->pdo = new PDO($this->dsn,$this->user,$this->password);
}
public function select($sql){
$arr = $this->pdo->prepare($sql);
return $arr;
}
}
$db = new Db('mysql:host=localhost;dbname=ou','root','root');
$sql = 'select * from user';
$user = $db->pdo->select($sql);
没有懂。第二节也无法看录播。白天还要上班,先交作业。请老师上课讲一下!