简体   繁体   English

MSSQL PDO查询始终返回0

[英]MSSQL PDO query returns always 0

I'm using mssql database to build an application. 我正在使用mssql数据库来构建应用程序。 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. 变量$ macc_id包含数字ex。 40 . 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. 当我调用此函数时,我总是得到0。我发现,如果我直接在查询中传递变量,它将很好地工作。 All the solutions I found were to remove ' ' . 我发现的所有解决方案都是删除''。 I don't use any. 我什么都不用。 What's the cause? 是什么原因

Thanks in advance. 提前致谢。

You get 0 beacuse you always get false (0). 您将得到0,因为您总会得到false(0)。

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

you function dont see variable $CONFIG['gamemaxaccounts'] and you always get false; 你的函数没有看到变量$ CONFIG ['gamemaxaccounts'],并且总是错误的;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM