获取count(字段名或*)的结果

@param string $field Mongo中此选项无效
@param bool $isMulti Mongo中此选项无效
@param bool|string $useMaster 是否使用主库 默认读取从库

@return mixed
162383
public function count($field = '*', $isMulti = false, $useMaster = false)
    {
        $cmd = [
            'count' => $this->getRealTableName(key($this->table)),
            'query' => $this->sql['where']
        ];

        $count = $this->runMongoCommand($cmd, $useMaster);
        return intval($count[0]['n']);
    }
1026868
public function count($field='*')
    {
        $this->getQuery()->type('select')->remove('fields')->set('count', $field);
        
        $result = $this->query();
        
        if ($result) {// get first row's value
            $result = current($result[0]);
        } else {
            $result = 0;
        }
        
        return $result;
    }
887299
public function sscan(&$Iterator, $field, $pattern = null, $count = null)
    {
        return $this->__call('sscan', [$field, &$Iterator, $pattern, $count]);
    }
1043943
public function select($offset = null, $limit = null, $useMaster = false)
    {
        is_null($offset) || $this->limit($offset, $limit);

        $filter = [];
        count($this->sql['orderBy']) > 0 && $filter['sort'] = $this->sql['orderBy'];
        count($this->sql['columns']) > 0 && $filter['projection'] = $this->sql['columns'];
        isset($this->sql['limit'][0]) && $filter['skip'] = $this->sql['limit'][0];
        isset($this->sql['limit'][1]) && $filter['limit'] = $this->sql['limit'][1];

        return $this->runMongoQuery(
            $this->getRealTableName(key($this->table)),
            $this->sql['where'],
            $filter,
            $useMaster
        );
    }
1185792
public function count(
        $query = [],
        $limit = null,
        $skip = null,
        $timeout = 2000
    ) {
        $this->getContext()->getLog()->profileStart($this->profileName . __FUNCTION__);
        $options = [
            'socketTimeoutMS' => $timeout
        ];
        if (!is_null($limit)) {
            $options['limit'] = $limit;
        }
        if (!is_null($skip)) {
            $options['skip'] = $skip;
        }
        $out = $this->mongoCollection->count($query, $options);
        if ($out === null) {
            return 0;
        }
        $this->getContext()->getLog()->profileEnd($this->profileName . __FUNCTION__);

        return $out;
    }
453752
public static function value($filters, $field, $ttl = null)
    {
        if (!is_string($field)) {
            throw new ParameterOrderException(__METHOD__ . ' field');
        }

        if ($ttl !== null && !is_int($ttl)) {
            throw new MisuseException('ttl must be a integer');
        }

        $model = new static;
        $pkName = $model->getPrimaryKey();

        $pkValue = null;
        if (is_scalar($filters)) {
            $pkValue = $filters;
            $filters = [$pkName => $pkValue];
        } elseif (is_array($filters)) {
            if (count($filters) === 1 && isset($filters[$pkName])) {
                $pkValue = $filters[$pkName];
            }
        }

        if ($ttl === null || $pkValue === null) {
            $rs = static::query(null, $model)->select([$field])->where($filters)->limit(1)->fetch(true);
            return $rs ? $rs[0][$field] : null;
        }

        $key = '_mp:models:value:' . $model->getSource() . ":$field:$pkValue:$ttl";
        if (($value = $model->_di->ipcCache->get($key)) !== false) {
            return $value;
        }

        $rs = static::query(null, $model)->select([$field])->whereEq($pkName, $pkValue)->limit(1)->fetch(true);
        $value = $rs ? $rs[0][$field] : null;

        $model->_di->ipcCache->set($key, $value, $ttl);

        return $value;
    }
528928
public function count($collectionName, $condition = [], $options = [])
    {
        $document = ['count' => $collectionName];

        if (!empty($condition)) {
            $document['query'] = (object) $this->buildCondition($condition);
        }

        return array_merge($document, $options);
    }
843808
public function increment(string $field, int $howMuch = 1): Update
    {
        return $this->set($field, new Expr("{$field} + {$howMuch}"));
    }
1351333
public function getMultiCount($collection, $column, array $values, array $extra = [])
    {
        $query = $this->model($collection)->whereIn($column, $values);

        return $this->addConditions($query, $extra)->count();
    }
62869
public function getInfoWithMultipleWhere($wheres = '', $field = 'id', $selectField = NULL)
    {
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $key => $value) {
                if (is_array($value['value'])) {
                    $this->db->where($value['field'], $value['value'], self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($value['field'], $value['value'], $value['operator']);
                }
            }
        } else {
            $this->db->where($field, $wheres, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->getOne($this->table, $selectField);
        if ($this->db->count > 0) {
            return $result;
        }

        return NULL;
    }
430662
public function hscan(&$Iterator, $field, $pattern = null, $count = null)
    {
        return $this->__call('hscan', [$field, &$Iterator, $pattern, $count]);
    }
954004
public function hasManyThrough($model, $through, $foreignKey = '', $throughKey = '', $localKey = '')
    {
        // 记录当前关联信息
        $model      = $this->parseModel($model);
        $through    = $this->parseModel($through);
        $localKey   = $localKey ?: $this->getPk();
        $foreignKey = $foreignKey ?: $this->getForeignKey($this->name);
        $throughKey = $throughKey ?: $this->getForeignKey($through);

        return new HasManyThrough($this, $model, $through, $foreignKey, $throughKey, $localKey);
    }
1079328
function addCount($key, $expire = 86400, $incrby = 1)
    {
        $key = self::PREFIX.$key;
        //增加计数
        if ($this->redis->exists($key))
        {
            return $this->redis->incr($key, $incrby);
        }
        //不存在的Key，设置为1
        else
        {
            return $this->redis->set($key, $incrby, $expire);
        }
    }
240792
function count($filter=NULL,array $options=NULL,$ttl=0) {
		if (!($subquery_mode=($options && !empty($options['group']))))
			$this->adhoc['_rows']=['expr'=>'COUNT(*)','value'=>NULL];
		$adhoc=[];
		foreach ($this->adhoc as $key=>$field)
			// Add all adhoc fields
			// (make them available for grouping, sorting, having)
			$adhoc[]=$field['expr'].' AS '.$this->db->quotekey($key);
		$fields=implode(',',$adhoc);
		if ($subquery_mode) {
			if (empty($fields))
				// Select at least one field, ideally the grouping fields
				// or sqlsrv fails
				$fields=preg_replace('/HAVING.+$/i','',$options['group']);
			if (preg_match('/mssql|dblib|sqlsrv/',$this->engine))
				$fields='TOP 100 PERCENT '.$fields;
		}
		list($sql,$args)=$this->stringify($fields,$filter,$options);
		if ($subquery_mode)
			$sql='SELECT COUNT(*) AS '.$this->db->quotekey('_rows').' '.
				'FROM ('.$sql.') AS '.$this->db->quotekey('_temp');
		$result=$this->db->exec($sql,$args,$ttl);
		unset($this->adhoc['_rows']);
		return (int)$result[0]['_rows'];
	}
171976
public function count($field = '*') {
        $this->statementContext->setFields("COUNT({$field}) AS __COUNT__");
        $row = $this->findOne();

        //SQL执行发生错误
        if ($row === false) {
            return false;
        }

        return $row['__COUNT__'];
    }
523243
public function count($field) {
        // Temporary key sum strings
        $_tmp_sum = [];
        
        if (is_array($field)) {
            foreach($field as $key => $value) {
                // Multiple fields
                array_push($_tmp_sum, 'COUNT(' . ($key ? $key : $value) . ') ' . ($key ? ' AS ' . $value : ''));
            }
        } else {
            // Single field
            array_push($_tmp_sum, 'COUNT(' . $field . ')');
        }
        
        $sql_query = 'SELECT ' . implode($_tmp_sum, ', ') .
                     ' FROM ' . $this->_table;
                     
        // Where statements
        if (count($this->_where)) {
            $sql_query .= ' WHERE ';
            $sql_query .= implode($this->_where, ' AND ');
            
            // or statements
            if (count($this->_or)) {
                $sql_query .= ' OR ';
                $sql_query .= implode($this->_or, ' AND ');
            }
        }
        
        // Set the query
        $this->_sql_query = $sql_query;
        
        return $this;
    }
127292
public function sum($field = 'id', $isMulti = false, $useMaster = false)
    {
        return $this->aggregation($field, $isMulti, '$sum', $useMaster);
    }