PDO_MySQL::count PHP Method

count() public method

根据条件返回数据的数量
public count ( $table, $conditions = [] ) : integer
$table string 数据表名
$conditions array 检索条件
return integer 数量的结果
    public function count($table, $conditions = array())
    {
        $key = getmypid();
        $params = array();
        $where = empty($conditions) ? '' : self::biuldMultiWhere($conditions, $params);
        $count_sql = implode(" ", array('SELECT COUNT(*) AS total_num FROM', 'zh_' . $table, $where));
        // echo "count_sql" . $count_sql . "\n";
        $stmt = $this->pdo->prepare($count_sql);
        $this->bind($params, $stmt);
        $result = $stmt->execute();
        if ($result === false) {
            var_dump("count error, args " . json_encode(func_get_args()));
            return false;
        }
        $count = $stmt->fetch(PDO::FETCH_ASSOC);
        $count = isset($count['total_num']) ? $count['total_num'] : 0;
        return intval($count);
    }