请多多包涵,因为我只是在学习 PDO。无论如何,我不断收到错误:
致命错误:在非对象上调用成员函数 prepare()
代码如下,我做错了吗?该函数本身正在另一个文件中被调用,如下所示:
$result = $database->confirmIPAddress($this->ip);
功能代码:
function confirmIPAddress($value) {
$stmt = $db->prepare("SELECT attempts, (CASE when lastlogin is not NULL and DATE_ADD(LastLogin, INTERVAL `.TIME_PERIOD.` MINUTE)>NOW() then 1 else 0 end) as Denied `.
` FROM `.TBL_ATTEMPTS.` WHERE ip = :ip");
$stmt->execute(array(':ip' => $value));
$data = $stmt->fetch(PDO::FETCH_ASSOC);
//Verify that at least one login attempt is in database
if (!$data) {
return 0;
}
if ($data["attempts"] >= ATTEMPTS_NUMBER)
{
if($data["Denied"] == 1)
{
return 1;
}
else
{
$this->clearLoginAttempts($value);
return 0;
}
}
return 0;
}