<?php
class SqlHelp{
public $dbname=数据库;
public $host="服务器";
public $username="用户名";
public $password="密码";
public $conn;
public function __construct(){
$this->conn=mysqli_connect($this->host,$this->username,$this->password,$this->dbname);
if(!$this->conn){
die("数据库连接失败".mysqli_connect_error());
}
// mysqli_close();
}
//执行sql语句
public function ExecuteSql($sql){
$res=mysqli_query($this->conn,$sql);
mysqli_close($this->conn);
return $res;
}
//查询所有
public function FetchAll($sql){
$res=mysqli_query($this->conn,$sql);
$res=mysqli_fetch_all($res,MYSQLI_ASSOC);
mysqli_close($this->conn);
// var_dump($res);
return $res;
}
//查询一条
public function FetchOne($sql){
$res=mysqli_query($this->conn,$sql);
$res=mysqli_fetch_assoc($res);
mysqli_close($this->conn);
// var_dump($res);
return $res;
}
}
网友评论