数据库包装成类
<?phpclass DBDA
{public $host = "localhost"; //服務器地址public $uid = "root"; //數(shù)據(jù)庫的用戶名public $pwd = "123"; //數(shù)據(jù)庫的密碼//執(zhí)行SQL語句,返回相應結果的函數(shù)//$sql是要執(zhí)行的SQL語句//$type是SQL語句的類型,0代表增刪改,1代表查詢//$db代表要操作的數(shù)據(jù)庫public function Query($sql,$type=1,$db="mydb"){//造連接對象$conn = new MySQLi($this->host,$this->uid,$this->pwd,$db);//判斷連接是否成功!mysqli_connect_error() or die("連接失敗!");//執(zhí)行SQL語句$result = $conn->query($sql);//判斷SQL語句類型if($type==1){//如果是查詢語句返回結果集的二維數(shù)組return $result->fetch_all();}else{//如果是其他語句,返回true或falsereturn $result;}}}
?
轉載于:https://www.cnblogs.com/hellodp/p/5339466.html
總結
- 上一篇: 梦到大家庭聚会预示着什么
- 下一篇: 《与mysql零距离接触》视屏学习笔记