PHP Mysqli 返回json格式

error){
    die("connect error,the error num is".$mysqli->connect_errno."the error message is" .$mysqli->connect_error);
}

$id=$_GET["id"];
//设置编码集
$mysqli->set_charset("Utf-8");

//写sql
$sql='select * from user where id=?';


$stmt=$mysqli->prepare($sql);


$stmt->bind_param("i",$id);

$stmt->execute();

$re=$stmt->get_result();


$array=array();
$inum=0;
while ($row=$re->fetch_assoc()){
    $array[$inum]=$row;
    $inum++;
}

$data=array();
$data['cont']=$array;
$data=json_encode($data);
header('content-type:application/json');
echo $data;

$re->close();
$stmt->close();

  

你可能感兴趣的:(PHP Mysqli 返回json格式)