我有以下功能: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