当前位置:Gxlcms > 数据库问题 > 封装 链接数据库类

封装 链接数据库类

时间:2021-07-01 10:21:17 帮助过:2人阅读

class SQL { public $host="localhost"; //数据库地址 public $uid="root"; //数据库用户名 public $pwd=""; //数据库密码 //执行SQL语句的方法 //参数:$sql要执行的SQL语句,$type是SQL语句类型0代表查询1代表其他,$db代表要操作的数据库 function Query($sql,$type=0,$db="mydb") { //1.造链接对象 $dbconnect =new MySQLi($this->host,$this->uid,$this->pwd,$db); //2.判断链接是否出错 !mysqli_connect_error() or die ("链接失败"); //3.执行SQL语句 $result=$dbconnect->query($sql); if($type==0) //查询 { return $result->fetch_all(); //返回一个二维数组的查询结果 } else //不是查询的时候 { return $result; //返回 true 或 false } } }

封装 链接数据库类

标签:

人气教程排行