Kosmas Papilis
Kosmas Papilis

Reputation: 57

MSSQL PDO query returns always 0

I'm using mssql database to build an application. To connect with the database I use

$db = new PDO('mssql:host=' . $CONFIG['dbserver'] . ';dbname=' . $CONFIG['lin2db'],$CONFIG['dbuser'], $CONFIG['dbpass']); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

And I've got this function inside a class.

public function getGameAccounts($macc_id){
$query = $this->db->prepare("SELECT COUNT(*) FROM user_account WHERE macc_id = ? ");
$query->bindValue(1, $macc_id); 
try{
    $query->execute();
    $rows = $query->fetchColumn();

    if($rows <= $CONFIG['gamemaxaccounts']){
        return true;
        }else{
            return false;
             }

    }catch(PDOException $e){
        die($e->getMessage());
        }
}

The variable $macc_id contains a number ex. 40 . When I call this function I always get 0. I Figured out that if I pass the variable directly inside the query it works fine. All the solutions I found were to remove ' ' . I don't use any. What's the cause?

Thanks in advance.

Upvotes: 0

Views: 97

Answers (1)

ZiupeX
ZiupeX

Reputation: 338

You get 0 beacuse you always get false (0).

    if($rows <= $CONFIG['gamemaxaccounts']){
    return true;
    }else{
        return false;
         }

you function dont see variable $CONFIG['gamemaxaccounts'] and you always get false;

Upvotes: 1

Related Questions