PHP 带有 mysql 多项选择的准备语句没有 return 任何东西
PHP prepared statement with mysql multiple selection doesn't return anything
下面的 php 代码没有 return 任何东西,而下面的 return 值,唯一的区别是多选。这是为什么?
(当我在我的浏览器中测试时,它没有拍摄任何东西)
我也尝试将选择放在 () 之间,但没有帮助。
非工作代码:
<?php
$mysqli = new mysqli("x", "w", "y", "z");
$coresite = "Abbasya";
$rowx = "103";
$columnx = "3";
$directionx = "Back";
if($stmt = $mysqli->prepare("SELECT CABOwner, EtisaatTeam FROM CAB WHERE (SiteName=? AND Row=? AND Col=? AND Direction=?)"))
{
$stmt->bind_param("ssss", $coresite, $rowx, $columnx, $directionx);
$stmt->execute();
$stmt->bind_result($cabinet);
while ($stmt->fetch())
{
echo json_encode($cabinet).",";
}
$stmt->close();
}
else{
$mysqli->close();
}
?>
一个选择的工作代码:
<?php
$mysqli = new mysqli("x", "w", "y", "z");
$coresite = "Abbasya";
$rowx = "103";
if($stmt = $mysqli->prepare("SELECT DISTINCT Col FROM CAB WHERE (SiteName=? AND Row=?)"))
{
$stmt->bind_param("ss", $coresite, $rowx);
$stmt->execute();
$stmt->bind_result($Col);
while ($stmt->fetch())
{
echo json_encode($Col).",";
}
$stmt->close();
}
else{
$mysqli->close();
}
?>
因为它 returns 多个值你需要绑定到多个变量。喜欢$stmt->bind_result($Col1, $Col2);
下面的 php 代码没有 return 任何东西,而下面的 return 值,唯一的区别是多选。这是为什么? (当我在我的浏览器中测试时,它没有拍摄任何东西) 我也尝试将选择放在 () 之间,但没有帮助。
非工作代码:
<?php
$mysqli = new mysqli("x", "w", "y", "z");
$coresite = "Abbasya";
$rowx = "103";
$columnx = "3";
$directionx = "Back";
if($stmt = $mysqli->prepare("SELECT CABOwner, EtisaatTeam FROM CAB WHERE (SiteName=? AND Row=? AND Col=? AND Direction=?)"))
{
$stmt->bind_param("ssss", $coresite, $rowx, $columnx, $directionx);
$stmt->execute();
$stmt->bind_result($cabinet);
while ($stmt->fetch())
{
echo json_encode($cabinet).",";
}
$stmt->close();
}
else{
$mysqli->close();
}
?>
一个选择的工作代码:
<?php
$mysqli = new mysqli("x", "w", "y", "z");
$coresite = "Abbasya";
$rowx = "103";
if($stmt = $mysqli->prepare("SELECT DISTINCT Col FROM CAB WHERE (SiteName=? AND Row=?)"))
{
$stmt->bind_param("ss", $coresite, $rowx);
$stmt->execute();
$stmt->bind_result($Col);
while ($stmt->fetch())
{
echo json_encode($Col).",";
}
$stmt->close();
}
else{
$mysqli->close();
}
?>
因为它 returns 多个值你需要绑定到多个变量。喜欢$stmt->bind_result($Col1, $Col2);