I am trying to convert MySQL to MySQLi. And I cannot figure out why it brakes on
$stmt2->execute();
and returns error:
Call to a member function execute() on a non-object
Any issue or valid implementing of it!?
// SQL condition "WHERE group=''" where `group` is empty (NULL)
$result = "SELECT id, name FROM table WHERE group='' ORDER BY array ASC";
if ($stmt = $mysqli->prepare($result)) {
$stmt->execute();
$stmt->bind_result($id, $name);
while ($stmt->fetch()) {
// SQL condition "WHERE group='$id'" where $id defined in $stmt->bind_result($id, $name);
$result2 = "SELECT name FROM table WHERE group='$id' ORDER BY array ASC";
$stmt2 = $mysqli->prepare($result2);
//$valid_stmt2 = $stmt2 === FALSE ? false : true;
echo $name . "\n";
//if ($valid_stmt2) {
// Error cased on $stmt2->execute();
$stmt2->execute();
$stmt2->bind_result($name2);
while ($stmt2->fetch()) {
echo 'related to: ' . $name2 . "\n";
}
$stmt2->close();
//}
}
$stmt->free_result();
$stmt->close();
}
This question might be related to Possible to use multiple/nested MySQLi statements? Unfortunately I did not find it helpful since it does not provide a valid example or resource for issue.
Update: Simplified code example with comments.
You first did
Then you want to use the
$id
to doHow would get result for that? If group equal empty string, then it will not equal
$id
(only if$id
is empty string too but that's non sense.)