链接类
conn=mysqli_connect($host,$user,$pwd,$database);
if($this->conn){
$this->conn->set_charset('utf8');
}
}
public function simple_query($sql){
$result=mysqli_query($this->conn,$sql);
return $result;
}
public function query($sql){
$result=mysqli_query($this->conn,$sql);
$arr=array();
while ($row = $result->fetch_assoc()){
array_push($arr,$row);
}
mysqli_free_result($result);
return json_encode($arr);
}
public function update($sql){
$result=mysqli_query($this->conn,$sql);
$arr=array();
if($result){
$arr['flag']=true;
$arr['msg']='Sucessful';
}else{
$arr['flag']=false;
$arr['msg']='Failure';
}
return json_encode($arr);
}
public function __destruct(){
mysqli_close($this->conn);
$this->conn=null;
}
}
?>
php 后端查询
$sql = "
select
user_username,
user_en
from
tbl_user
";
$result=$sqls->simple_query($sql);
$arr=array();
$inum=0;
while ($row = $result->fetch_assoc()){
$arr[$inum]['user_username'] = $row['user_username'];
$arr[$inum]['user_en'] = $row['user_en'];
$inum++;
}
mysqli_free_result($result);
echo json_encode($arr);
postman结果
海报
0 条评论
198
相关文章
本站已关闭游客评论,请登录或者注册后再评论吧~