php - PDO Fatal error: Call to a member function prepare() on a non-object -


this question has answer here:

please bear me i'm learning pdo. anyway keep getting error:

fatal error: call member function prepare() on non-object

the code below, doing wrong? function being called out on file so:

$result = $database->confirmipaddress($this->ip); 

function code:

function confirmipaddress($value) {     $stmt = $db->prepare("select attempts, (case when lastlogin not null , date_add(lastlogin, interval `.time_period.` minute)>now() 1 else 0 end) denied `.     ` `.tbl_attempts.` ip = :ip");     $stmt->execute(array(':ip' => $value));     $data = $stmt->fetch(pdo::fetch_assoc);      //verify @ least 1 login attempt 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;     } 

prepare() returns false if there's parse error, or else throws exception if have configured pdo use error mode.

your statement has syntax problems. appear embedding php constant table name , time period, have used back-ticks delimit string. need use double-quotes in case.

current statement:

$stmt = $db->prepare("select attempts, (case when lastlogin not null ,     date_add(lastlogin, interval `.time_period.` minute)>now() 1 else 0 end)      denied `.   ` `.tbl_attempts.` ip = :ip"); 

should be:

$stmt = $db->prepare("select attempts, (case when lastlogin not null ,     date_add(lastlogin, interval ".time_period." minute)>now() 1 else 0 end)      denied   `".tbl_attempts."` ip = :ip"); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -