【php】Mysql访问类

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;
    }
}


你可能感兴趣的:(【php】Mysql访问类)