1.做封装类
<?php class DBDA { //成员变量 数据库的四个条件 public $host="localhost"; public $uid = "root"; public $pwd = "123"; public $dbname = "mydb"; //成员方法 public function Query($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $r = $db->query($sql); if($type==1) { return $r->fetch_all();//如果等于1就返回查询 } else { return $r;//否则返回增删改 } } }
2.
<?php include("./DBDA.class.php");//调用封装类 $db = new DBDA();