1 回答
TA贡献1859条经验 获得超6个赞
您可以尝试以下方法:
始终检查
sqlsrv_query()
执行结果。始终尝试使用参数化语句。函数
sqlsrv_query()
既做语句准备又做语句执行,可用于执行参数化查询。检查
json_encode()
调用的结果。修复输入错误(例如
"signed_status" => 1,
应该是"signed_status" => 1
)。
示例脚本,基于您的代码:
<?php
if (isset($_GET["scard"])) {
$scard = $_GET["scard"];
$data = array();
$sql = "SELECT * FROM training_record WHERE cardref_no = ?";
$params = array($scard);
$q = sqlsrv_query($conn, $sql, $params);
if ($q === false) {
echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
exit;
}
while ($rw = sqlsrv_fetch_array($q, SQLSRV_FETCH_ASSOC)) {
$data[] = array(
"employee_no" => $rw["employee_no"],
"dept_id" => $rw["dept_id"],
"name_th" => $rw["name_th"],
"surname_th" => $rw["surname_th"],
"signed_status" => 1
);
}
$json = json_encode($data);
if ($json === false) {
echo json_last_error_msg();
exit;
}
echo $json;
}
?>
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报