<?php
header("Content-Type: text/html; charset=utf-8") ;
$distributeId = $_GET['distributeId'];
$user = new mysqli();
if($user)
{
$user->connect("localhost", "root", "123456", "test_db");
if (mysqli_connect_errno())
{
$arr = array(
'code'=>'400',
'info'=>"系统错误!"
);
echo json_encode($arr,JSON_UNESCAPED_UNICODE);
exit();
}
}
else
{
$arr = array(
'code'=>'400',
'info'=>"系统错误!",
);
echo json_encode($arr,JSON_UNESCAPED_UNICODE);
exit();
}
$user->query("set names 'utf8' ");
$query = "SELECT * FROM testtbl where distributeId = '$distributeId'";
//Use a variable to save result
if($result = $user->query($query))
{
$arr = array(
'code'=>'200',
'info'=>"retrieve data successfully!",
'num'=>$result->num_rows,
'data'=>$result->fetch_all()
);
echo json_encode($arr,JSON_UNESCAPED_UNICODE);
}
else
{
$arr = array(
'code'=>'400',
'info'=>"获取数据失败!"
);
echo json_encode($arr,JSON_UNESCAPED_UNICODE);
}
$user->close();
?>
PHP MySQL 数据检索
本文介绍了一个使用PHP连接MySQL数据库并根据'distributeId'参数检索数据的方法。通过建立数据库连接,执行SQL查询,处理查询结果,并将结果以JSON格式返回。
7382

被折叠的 条评论
为什么被折叠?



