Count number of results for query.

@param string $field
@return integer
@throws \DomainException
160500
public function count($field = '*')
    {
        if ($field !== '*' && !in_array($field, $this->getFields())) {
            throw new \DomainException(__METHOD__ . '|Field is not allowed ! (field: ' . $field . ')');
        }

        $query = 'SELECT COUNT(' . $field . ') AS NB_RESULTS FROM ' . $this->table . ' ' . $this->getQueryWhere();

        $statement = $this->db->prepare($query);
        $statement->execute($this->binds);

        $this->clear();

        return (int) $statement->fetchColumn(0);
    }
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;
    }
1371264
function Count($where = null) {
		$this->LoadSchema();
		if ($this->UseCache('count')) {
			$cacheid = md5(json_encode($where));

			if ($value = $this->GetCache('count', $cacheid))
				return $value;
		}

		$this->ResetQuery(array(
			'method' => 'count',
			'table' => $this->table,
			'where' => $where,
		));

		$this->Trigger('access', $where);
		if (!$this->continue)
			return 0;

		$this->Trigger('pull', $where);
		if (!$this->continue)
			return 0;

		$this->Trigger('getall', $where);
		if (!$this->continue)
			return 0;

		$this->db->select('COUNT(*) AS count');
		$this->db->from($this->table);
		if ($where = $this->FilterFields($where, 'where'))
			$this->db->where($where);
		$row = $this->db->get()->row_array();
		if (!$this->continue)
			return 0;

		return isset($cacheid) ? $this->SetCache('count', $cacheid, $row['count']) : $row['count'];
	}
741858
public function count($type='admin.web')
    {
        return $this->task->scopeQuery(function($query)use($type){
                return $query->whereUserId(user_id($type))
                            ->whereUserType(user_type($type));
            })->count();
    }
495389
public function count()
    {

        switch ($this->mode) {

            case "mysql":
                $rows = $this->result->num_rows;
                break;

            case "postgres":
            case "redshift":
                $rows = pg_num_rows($this->result);
                break;

            case "odbc":
                $rows = odbc_num_rows($this->result);

                # The above function is unreliable, so if we got a zero count then double check it
                if ($rows < 1) {
                    $rows = 0;

                    /**
                     * If it is an update/delete then we just have to trust the odbc_num_rows() result,
                     * however it is some kind of select, then we can manually count the rows returned.
                     */
                    if (odbc_num_fields($this->result) > 0) {
                        $position = $this->position;
                        $this->seek(0);
                        while ($this->getNextRow()) {
                            ++$rows;
                        }
                        $this->seek($position);
                    }
                }
                break;

            case "sqlite":
                $rows = 0;
                while ($this->result->fetchArray()) {
                    $rows++;
                }
                $this->seek($this->position);
                break;

            case "mssql":
                $rows = mssql_num_rows($this->result);
                break;

            case "mssqlsrv":
                $rows = sqlsrv_num_rows($this->result);
                break;
        }

        if ($rows === false || $rows < 0) {
            throw new \Exception("Failed to get the row count from the result set");
        }

        return $rows;
    }
1233560
public function count($field = '*')
    {
        if ($this->_union) {
            throw new NotSupportedException('Union query is not support to get total rows');
        }

        $copy = clone $this;

        $copy->_fields = "COUNT($field) as [row_count]";
        $copy->_limit = null;
        $copy->_offset = null;
        $copy->_order = null;
        $copy->_index = null;

        $copy->_sql = $copy->_buildSql();

        if ($copy->_group === null) {
            $result = $copy->getConnection()->fetchOne($copy->_sql, $copy->_bind);

            /** @noinspection CallableParameterUseCaseInTypeContextInspection */
            $rowCount = (int)$result['row_count'];
        } else {
            $result = $copy->getConnection()->fetchAll($copy->_sql, $copy->_bind);
            $rowCount = count($result);
        }

        return $rowCount;
    }
1053660
public function count($alias = null)
    {
        // prepare new query
        $q = $this->dsql()->del('fields')->del('order');

        // add expression field to query
        return $q->field($q->count(), $alias);
    }
1064185
public function count()
    {
        if (isset($this->_resultset)) {
            return $this->_resultset->count();
        } elseif (isset($this->_limit) || isset($this->_group)) {
            return $this->execute()->count();
        } else {
            $query = clone $this;

            return (int)$query->select("count(*) count")->execute()->scalar();
        }
    }
1012853
public function count($expression, $type = Query::TYPE_CSS)
    {
        $expression = Query::compile($expression, $type);
        $expression = sprintf('count(%s)', $expression);

        return (int) $this->createXpath()->evaluate($expression);
    }
104561
private function query($count)
    {
        $this->applyQueryFilters();

        if ($this->hasTranslating()) {
            $this->applyTranslationFilter();
        }

        if ($this->orderBy()) {
            $this->query = $this->query->orderBy(
                                $this->orderBy(),
                                $this->sortBy()
                            );
        }

        if ($count) {
            return $this->query->count();
        }

        if ($this->perPage > 0) {
            return $this->query->paginate($this->perPage);
        }

        return $this->query->get();
    }
80583
public function count(array $query = [])
    {
        $partial = Inflector::pluralize($this->getResourceName()).'/count';

        return $this->client->get($partial, $query)['count'];
    }
88202
public function getNumberOf(string $table, array $fields, array $values, string $connectionPhrase = "AND"): int
    {
        try {
            $this->db->beginTransaction();

            $query = "SELECT count(*) as numberOfEntities FROM $table ";

            $query = $query . $this->buildWhereCondition($fields, $connectionPhrase);

            /** @var PDOStatement $stmt */
            $stmt = $this->db->prepare($query);
            $stmt->execute($values);

            $this->db->commit();
            $result = $stmt->fetch();

            return $result['numberOfEntities'];
        } catch (PDOException $e) {
            $this->db->rollBack();
            throw new PDOException($e);
        }
    }
1289138
public function count($query = [])
    {
        if ($query instanceof Closure) {
            $callback = $query;
            $query = new Query\Where();
            $callback($query);
        }

        if ($query instanceof Query\Where) {
            $query = $query->getWhere();
        }

        if (! is_array($query)) {
            throw new \InvalidArgumentException('The count query should be an array.');
        }

        return $this->collection->count($query);
    }
813029
public function aggregate(Query $query, $function, $field) {
        $query->fields(
            Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
        );

        $results = $this->getDriver()
            ->setContext('read')
            ->executeQuery($query)
            ->find();

        if (isset($results[0])) {
            return (int) $results[0]['aggregate'];
        }

        return 0;
    }
1043852
public function find($id)
    {
        $resultSet = $this->findAllBy(array(
            $this->getIdColumn() => $id,
        ));

        if (count($resultSet)) {
            return $resultSet[0];
        }

        throw new \DomainException(
            sprintf(
                '%s record not found by %s %s',
                $this->getTableName(),
                $this->getIdColumn(),
                $id
            )
        );
    }
264890
private function getCount($column)
    {
        $alias = 'count';

        // Save initial state
        $original = clone $this->queryBuilder;
        $bindings = $this->bindings;

        // Set guessed query and execute it
        $this->queryBuilder->setQueryString($this->queryBuilder->guessCountQuery($column, $alias));
        $count = $this->query($alias);

        // And finally restore initial state
        $this->queryBuilder = $original;
        $this->bindings = $bindings;

        return $count;
    }
515537
public function increment(string $field, int $num) : int
        {
                return intval($this->_redis->hincrby($this->_key, $field, $num));
        }