我正在尝试将 MySQL 转换为 MySQLi。我不知道为什么它会刹车
$stmt2->execute();
并返回错误:
Call to a member function execute() on a non-object
有任何问题或有效实施它!?
// 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();
}
这个问题可能与可能使用多个/嵌套的 MySQLi 语句有关?不幸的是,我没有发现它有帮助,因为它没有提供有效的示例或问题资源。
更新:带有注释的简化代码示例。