0

i have following simple class with static method in php which check if record exist then return the record otherwise return false

  class db{

      public static function isRecord($q,$parameters){  
        $a=self::getinstance()->prepare($q);
        $a->execute($parameters);
        $r=$a->fetch(PDO::FETCH_NUM);
        if($r[0]) return $r[0]; 
        if(!$r[0] || $r[0]==0 ) return false;
     }
  }

usage

  $e=db::isRecord("SELECT itemdesc FROM temptable WHERE invuser=? ",array($invuser));

returns $e as expected.

but if i use with in simple function like this

function canEnterincart(){
    return db::isRecord("SELECT itemdesc FROM temptable WHERE invuser=? ",array($invuser));
}

var_dump(canEnterincart()) always return false even if the record exist.

Is this something wrong with the code?

1 Answers1

0

You should pass the variable as a parameter of the method, like this:

function canEnterincart($invuser){
    return db::isRecord("SELECT itemdesc FROM temptable WHERE invuser=? ",array($invuser));
}
clami219
  • 2,958
  • 1
  • 31
  • 45