在pdo中使用函数获取count(*)的问题

i have a problem to use pdo for get COUNT(*).

    (...)

    public function getRowCount($sql, $bin = null)
    {
        $a = $this->conn->prepare($sql);
        if (!is_null($bin)) {
            foreach ($bin as $i => $val) {
                $a->bindParam(":$i", $val);
            }
        }
        $a->execute();
        return $a->fetchColumn();
    }

    (...)

如果我使用它,它将对我有用:

    // $obj = new class()
    echo $obj->getRowCount("SELECT COUNT(*) FROM `table_name` WHERE `a`=:a", [
        'a' => 'ABC'
    ]);

    // 1 or 2 and ...

但这不适用于两个条件:

    // $obj = new class()
    echo $obj->getRowCount("SELECT COUNT(*) FROM `table_name` WHERE `a`=:a AND `b`=:b", [
        'a' => 'ABC',
        'b' => 'DEF'
    ]);

    // only 0
评论