<?php class DBDA { public $host="localhost"; //数据库地址 public $uid = "root"; //数据库用户名 public $pwd = ""; //密码 //执行sql语句,返回相应的结果 //参数:$sql表明执行的sql语句;$type是sql语句类型0表明查询,1表明其余;$db表明操做的数据库 public 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; } } }
在之后的数据库查询中能够直接调用php