我有以下功能:bind_param()在非對象錯誤
public function detail($detail, $table, $column, $value) {
if(is_array($detail)) {
$data = array();
foreach($detail as $key) {
$stmt = $this->mysqli->prepare("SELECT `$key` FROM `$table` WHERE `$column` = ?");
if(is_numeric($value)) {
$stmt->bind_param('i', $value);
} else {
$stmt->bind_param('s', $value);
}
$stmt->execute();
$stmt->bind_result($detail);
$stmt->fetch();
$data[] = $detail;
}
return $data;
} else {
$stmt = $this->mysqli->prepare("SELECT `$detail` FROM `$table` WHERE `$column` = ?");
if(is_numeric($value)) {
$stmt->bind_param('i', $value);
} else {
$stmt->bind_param('s', $value);
}
$stmt->execute();
$stmt->bind_result($detail);
$stmt->fetch();
return $detail;
}
}
此功能運作良好,直到我使用的陣列。使用這個函數的方式是這樣的:$db->detail('username', 'users', 'id', 1)
這將返回id爲1的用戶的用戶名(這可以很好地工作)。就像我說的,當我使用數組因此,例如問題開始:
$details = array('username', 'active', 'registered');
$details = $db->detail($details, 'users', 'id', 1);
print_r($details);
錯誤指向$stmt->bind_param('i', $value);
在if(is_array())
。我已經試過了:bind_param on a non-object的回答,但這並沒有幫助我;我仍然得到同樣的錯誤。 我希望有人知道如何修復我的Fatal error: Call to a member function bind_param() on a non-object
錯誤。
在此先感謝。
很可能是因爲'準備()'失敗,這就是爲什麼當你綁定,它沒有工作 – Ghost 2014-09-21 10:06:34
可能是因爲您覆蓋變量$詳細其中失敗準備在下一次迭代 – 2014-09-21 10:26:52