prepared statement retunerer kun een række
HejsaJeg har en funktion der hente noget af en tabel til listevisning.
Men den nægter at returnere mere end een række, trods sql'en kørt direkte i db'en sagtens kan finde alle rækker.
Hvad overser jeg???
Det mest mærkelige er, at jeg bruger samme funktion andre steder uden nogen problemer...
//put data in the database
if (!($statement = $mysqli->prepare('SELECT SQID, Type, Question, NextQuestion, AlternativeNextQuestion, PageNumber
FROM '.QuestionsTable.'
WHERE SQID IN (?)'))) {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': Prepare failed: ('.$mysqli->errno.') '.$mysqli->error));
throw new Exception($mysqli->error, $mysqli->errno);
exit();
}
if (!($statement->bind_param('s', $strQID))) {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': bind_param failed: ('.$statement->errno.') '.$statement->error));
throw new Exception($statement->error, $statement->errno);
exit();
}
if (!$statement->execute()) {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': Execute failed: ('.$statement->errno.') '.$statement->error));
throw new Exception($statement->error, $statement->errno);
exit();
}
if (!$statement->store_result()) {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': store_result failed: ('.$statement->errno.') '.$statement->error));
throw new Exception($statement->error, $statement->errno);
exit();
}
// If the Question exists get variables from result.
if($statement->bind_result($SQID, $Type, $Question, $NextQuestion, $AlternativeNextQuestion, $PageNumber)) {
// remember to actually GET the data!
if ($statement->fetch()) {
$output = array();
$output[] = array('SQID'=>$SQID, 'Type'=>$Type, 'Question'=>$Question, 'NextQuestion'=>$NextQuestion, 'AlternativeNextQuestion'=>$AlternativeNextQuestion, 'PageNumber'=>$PageNumber);
while ($statement->fetch()) {
$output[] = array('SQID'=>$SQID, 'Type'=>$Type, 'Question'=>$Question, 'NextQuestion'=>$NextQuestion, 'AlternativeNextQuestion'=>$AlternativeNextQuestion, 'PageNumber'=>$PageNumber);
echo $SQID."<br>";
}
} else {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': fetch failed: ('.$statement->errno.') '.$statement->error));
throw new Exception($statement->error, $statement->errno);
exit();
}
} else {
$objLog->LogIt(array('LogType' => '3', 'LogText' => __FUNCTION__.': bind_result failed: ('.$statement->errno.') '.$statement->error));
throw new Exception($statement->error, $statement->errno);
exit();
}
$statement->close();
return json_encode($output);