我想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的语句? 不幸的是我没有发现它有用,因为它没有提供有效的例子或资源的问题。
更新:有评论简化代码示例。