php封装类

封装类

 1 <?php
 2 class DBDA{
 3     public $host = "localhost";
 4     public $uid = "root";
 5     public $pwd = "";
 6     public $dbname = "0710";
 7     
 8     /*
 9         query方法:执行用户给的SQL语句,并返回相应的结果
10         $sql:用户需要执行的SQL语句
11         $type:用户需要执行的SQL语句的类型
12         return:如果是增删改返回true或false,如果是查询返回二维数组
13     */
14     public function query($sql,$type=0){
15         $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
16         if(mysqli_connect_error()){
17             return "连接失败!";
18         }
19         $result = $db->query($sql);
20         if($type){
21             return $result;
22         }else{
23             return $result->fetch_all();
24         }
25     }
26 }
原文地址:https://www.cnblogs.com/sunzhenkun/p/7470551.html