我想將MySQL轉換爲MySQLi。我想不通爲什麼它剎車如何實現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();
}
這個問題可能與Possible to use multiple/nested MySQLi statements?不幸的是我沒有發現它有用,因爲它沒有提供有效的例子或資源的問題。
更新:帶有註釋的簡化代碼示例。
@hakre它不是重複http://stackoverflow.com/questions/8999691/call -to-一個成員函數-執行上-A-非對象。我改變'$ stmt2 = $ mysqli-> prepare(「SELECT url,name FROM links WHERE group ='?'ORDER BY array ASC」);'並添加了'$ stmt2-> bind_param(「i」,$ id); ',但它仍然不起作用。任何人都可以提供一個工作示例第二個'while()'必須根據條件返回查詢結果 - 從第一個'while()'得到'$ id'。 – Binyamin
可笑社區如何看到這個問題的確切重複http://stackoverflow.com/questions/8999691/call-toa-a-member-function-execute-on-a-non-object。要求重新檢查。 – Binyamin