php - mysql中的SQLSRV绑定参数
问题描述
我正在尝试将此 mysql 代码转换为使用 sqlsrv
$planeId = $_GET["pid"];
$conn = OpenCon();
$sql = "SELECT id, pid, fullname, tat, date, engine1, engine2, engine3, engine4 FROM oil WHERE pid = ? order by date desc";
$stmnt = $conn->prepare($sql);
$stmnt->bind_param("s", $planeId);
$stmnt->bind_result($id, $pid, $fullname, $tat, $date, $engine1, $engine2, $engine3, $engine4);
$stmnt->execute();
$theRows = Array();
while ( $stmnt->fetch() )
{
$aRow['id'] = "$id";
$aRow['pid'] = "$pid";
$aRow['fullname'] = $fullname;
$aRow['tat'] = $tat;
$aRow['date'] = $date;
$aRow['engine1'] = $engine1;
$aRow['engine2'] = $engine2;
$aRow['engine3'] = $engine3;
$aRow['engine4'] = $engine4;
$theRows[] = $aRow;
}
$stmnt->close();
echo json_encode($theRows);
CloseCon($conn);
这是我到目前为止所做的,但我错过了 bind-param 函数,不知道如何实现它。因为输出一直像这样
[{"id":"","pid":"","fullname":null,"tat":null,"date":null,"engine1":null,"engine2":null,"engine3":null,"engine4":null}]
即使我知道 Microsoft DB 中有一个条目
$planeId = $_GET["pid"];
$theRows = Array();
$conn = OpenCon();
$query = "SELECT id, pid, fullname, tat, date, engine1, engine2, engine3, engine4 FROM oil WHERE pid = ? order by date desc";
//$stmnt = $conn->prepare($query);
$stmnt = sqlsrv_prepare($conn, $query, array(&$planeId));
if (sqlsrv_execute($stmnt) === false){
die( print_r( sqlsrv_errors(), true));
}
else{
while ( sqlsrv_fetch($stmnt) )
{
$aRow['id'] = "$id";
$aRow['pid'] = "$pid";
$aRow['fullname'] = $fullname;
$aRow['tat'] = $tat;
$aRow['date'] = $date;
$aRow['engine1'] = $engine1;
$aRow['engine2'] = $engine2;
$aRow['engine3'] = $engine3;
$aRow['engine4'] = $engine4;
$theRows[] = $aRow;
}
echo json_encode($theRows);
}
CloseCon($conn);
解决方案
推荐阅读
- java - 我正在研究以下 springboot 示例,我得到 ApplicationContextException
- python - 如何在机器人框架的套件设置中“运行关键字 if tag="debug"”
- nuxt.js - 如何在 Netlify 上将 SSR 与 Nuxt.js 一起使用
- google-chrome-devtools - Chrome Devtools:我可以在鼠标悬停时自定义信息吗
- python - 如何通过单击 django 中的一个按钮在选项卡中提交 3 个表单?
- ios - Apple Push Notification 的 .p12 证书是否不需要 APNs Auth Key?
- javascript - 应用 CSS 时为 font-family 值添加了额外的引号
- python-3.x - Kivy - 所有动态创建的按钮(在 for 循环中)返回相同的参数
- excel - 在 Windows 中打开 Mac Office 365 Excel 文件 - “我们发现某些内容有问题”
- asp.net - 405 用于访问此页面的 HTTP 动词在 azure 广告之后是不允许的