Sheriff Said Elahl Sheriff Said Elahl - 7 months ago 15
PHP Question

PHP prepared statement with mysql multiple selection doesn't return anything

the below php code doesn't return anything while the below one returns value, the only difference is the multiple selection. why is that?
(When I test is in my browser it dosen't shot anything)
I also tried to put the selection between () but doesn't help.

NON Working code:

<?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();
}


?>

Working Code with one selection:

<?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();
}
?>

Answer

Since it returns multiple values you need to bind to multiple variables. Like $stmt->bind_result($Col1, $Col2);