Get count of rows

@return int
500446
public function count()
    {
        // Get the current statements
        $originalStatements = $this->statements;

        unset($this->statements['orderBys']);
        unset($this->statements['limit']);
        unset($this->statements['offset']);

        $count = $this->aggregate('count');
        $this->statements = $originalStatements;

        return $count;
    }
105037
protected function countTotalRows()
    {
        $source = $this->getSource();
        /** @var \Doctrine\ORM\Query\Expr\Select $select */
        $source->resetDQLPart('select')->setFirstResult(0)->select('count(' . $this->entityAlias . ')');
        return (int)$source->getQuery()->getSingleScalarResult();
    }
252964
public function getRowsCount()
    {
        if (is_null($this->summaryRow)) {
            return count($this->rows);
        } else {
            return count($this->rows) + 1;
        }
    }
1044746
public function count()
    {
        if ($this->_rowCount === null) {
            $rowCount = $this->_query->count();
            $this->setRowCount($rowCount);
        }

        return $this->_rowCount;
    }
363316
public function foundRows()
    {
        if ($this->hasOption('SQL_CALC_FOUND_ROWS')) {
            return (int) $this->owner->getOne('select found_rows()');
        }
        /* db-compatible way: */
        $c = clone $this;
        $c->del('limit');

        return (int) $c->fieldQuery('count(*)')->getOne();
    }
876995
public function getRowCount() {
    $mapper = ObjectFactory::getInstance('persistenceFacade')->getMapper($this->type);
    if ($this->table) {
      $table = !is_array($this->table) ? $this-> table : key($this->table);
      // use pk columns for counting
      $countColumns = array_map(function($valueName) use ($mapper, $table) {
        return $mapper->quoteIdentifier($table).'.'.$mapper->quoteIdentifier($mapper->getAttribute($valueName)->getColumn());
      }, $mapper->getPkNames());
    }
    else {
      // fallback if table is not defined: take first column
      $adapter = $this->getAdapter();
      $columns = $this->processSelect($adapter->getPlatform());
      $countColumns = [$columns[$this->quantifier ? 1 : 0][0][0]];
    }

    $countStatement = clone $this;
    $countStatement->reset(Select::COLUMNS);
    $countStatement->reset(Select::LIMIT);
    $countStatement->reset(Select::OFFSET);
    $countStatement->reset(Select::ORDER);
    $countStatement->reset(Select::GROUP);
    // remove all join columns to prevent errors because of missing group by for non aggregated columns (42000 - 1140)
    $joins = $countStatement->joins->getJoins();
    $countStatement->reset(Select::JOINS);
    foreach ($joins as $key => $join) {
      // re add join without cols
      $countStatement->join($join["name"], $join["on"], [], $join["type"]);
    }

    // create aggregation column
    $countStatement->columns(['nRows' => new \Zend\Db\Sql\Expression('COUNT('.$this->quantifier.' '.join(', ', $countColumns).')')]);

    $countStatement->id = $this->id != self::NO_CACHE ? $this->id.'-count' : self::NO_CACHE;
    try {
      $result = $countStatement->query();
      $row = $result->fetch();
      return $row['nRows'];
    }
    catch (\Exception $ex) {
      self::$logger->error("The query: ".$countStatement->__toString()."\ncaused the following exception:\n".$ex->getMessage());
      throw new PersistenceException("Error in persistent operation. See log file for details.");
    }
  }
1121904
public function count()
    {
        $this->select("COUNT(" . $this->getPrimaryKey() . ") as count");

        try {
            $results = $this->query();
        } catch (\PDOException $e) {

            throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);
        }

        $results = $results->fetchAssoc();

        return $results[0]['count'];
    }
287589
public function rowCount()
    {
        try {
            return $this->_stmt->rowCount();
        } catch (PDOException $e) {
            // require_once 'Zend/Db/Statement/Exception.php';
            throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
1118176
public function rowCount()
    {
        if (!$this->_adapter) {
            return false;
        }
        $mysqli = $this->_adapter->getConnection();
        return $mysqli->affected_rows;
    }
497713
public function numberOfRows()
    {
        if (isset($this->statement)) {
            $this->statement->store_result();
            return $this->statement->num_rows ?: $this->statement->affected_rows;
        } else if (isset($this->result)) {
            return $this->result->num_rows;
        } else {
            throw new Exception('Error: The database result resource is not currently set.');
        }
    }
1181402
public function count()
    {

        $query = $this->query();

        // Remove unsupported count query keys

        unset(
            $query["size"],
            $query["from"],
            $query["body"]["_source"],
            $query["body"]["sort"]
        );

        return $this->connection->count($query)["count"];
    }
913484
public function count( $conditions = array() )
	{
		$conditions	= $this->getConditionQuery( $conditions, FALSE, TRUE, TRUE );					//  render WHERE clause if needed, foreign cursored, allow functions
		$conditions	= $conditions ? ' WHERE '.$conditions : '';
		$query	= 'SELECT COUNT(`%s`) as count FROM %s%s';
		$query	= sprintf( $query, $this->primaryKey, $this->getTableName(), $conditions );
		return (int) $this->dbc->query( $query )->fetch( \PDO::FETCH_OBJ )->count;
	}
879414
public static function countAll () : int
	{
        $dbObject  	= Database::getInstance();
		$sqlQuery 	= "SELECT COUNT(*) FROM ".static::$tableName;
		$resultSet 	= $dbObject->query($sqlQuery);
		$row 		= Database::fetchAssoc($resultSet);
		return (int) array_shift($row);
	}
431959
public function fetched_count()
    {
        if ($this->statement) {
            return $this->statement->num_rows;
        }
        
        if (!$this->mysqli_result) {
            $this->last_error_id = "db_result_error";
            return false;
        }
        
        // by update, insert, delete it is not an object
        // by select it is an object
        // crazy!
        
        if (!is_object($this->mysqli_result)) {
            return false;
        }
        
        return $this->mysqli_result->num_rows;
    }
290651
public function count(): int
    {
        $query = $this->viewable->views();

        $cacheKey = Key::createForEntity($this->viewable, $this->period ?? Period::create(), $this->unique, $this->collection);

        if ($this->shouldCache) {
            $cachedViewsCount = $this->cache->get($cacheKey);

            // Return cached views count if it exists
            if ($cachedViewsCount !== null) {
                return (int) $cachedViewsCount;
            }
        }

        if ($period = $this->period) {
            $query->withinPeriod($period);
        }

        $query->where('collection', $this->collection);

        if ($this->unique) {
            $viewsCount = $query->uniqueVisitor()->count('visitor');
        } else {
            $viewsCount = $query->count();
        }

        if ($this->shouldCache) {
            $this->cache->put($cacheKey, $viewsCount, $this->cacheLifetime);
        }

        return $viewsCount;
    }
45016
public static function fetchListCount()
    {
        $rows = eZPersistentObject::fetchObjectList( self::definition(),
                                                     array(),
                                                     null,
                                                     false,
                                                     null,
                                                     false, false,
                                                     array( array( 'operation' => 'count( * )',
                                                                   'name' => 'count' ) ) );
        return $rows[0]['count'];
    }
769589
public function fetched_count()
    {
        if (!$this->statement) {
            $this->last_error_id = "db_result_error";
            return false;
        }
        
        if (!is_resource($this->statement)) {
            return false;
        }
        
        /*
        If the cursor is SQLSRV_CURSOR_STATIC or other than
        SQLSRV_CURSOR_FORWARD, retreiving of the data
        has sometimes very poor performance. Not the query execution,
        but the data retrieving!
    
        The default is SQLSRV_CURSOR_FORWARD, but it is not possible
        to get fetched_count by this type of cursor. So we sacrifice
        the possibility to get fetched_count for the preformance.
        The preformance is more important.
    
        no more relevant in new version of driver
        */
        
        return @sqlsrv_num_rows($this->statement);
    }