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.