Blogger Information
Blog 29
fans 0
comment 1
visits 19668
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11.27作业-PHP类
风清扬
Original
830 people have browsed it
  1. 把 php公用方法库中的 数据库操作函数, 重写到 Db类中。

class Db{
public $dsn;
public $user;
public $password;

  1. public $pdo;
  2. // 类里面的方法,不需要顺序。
  3. public function __construct($dsn,$user,$password){
  4. $this->dsn = $dsn;
  5. $this->user = $user;
  6. $this->password = $password;
  7. $this->connect();
  8. }
  9. public function connect(){
  10. $this->pdo = new PDO($this->dsn,$this->user,$this->password);
  11. }
  12. public function select($sql){
  13. $arr = $this->pdo->prepare($sql);
  14. return $arr;
  15. }
  16. }
  17. $db = new Db('mysql:host=localhost;dbname=ou','root','root');
  18. $sql = 'select * from user';
  19. $user = $db->pdo->select($sql);
  20. 没有懂。第二节也无法看录播。白天还要上班,先交作业。请老师上课讲一下!
Correcting teacher:查无此人查无此人

Correction status:unqualified

Teacher's comments:11月29号课上,已经把这个作业讲解了。 你去看看,在把作业提交上来。如果不会,在来问我
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post