src/xPDO/xPDO.php
public function getCount($className, $criteria = null) {
        $count = 0;
        if ($query = $this->newQuery($className, $criteria)) {
            $stmt = null;
            $expr = '*';
            if ($pk = $this->getPK($className)) {
                if (!is_array($pk)) {
                    $pk = array($pk);
                }
                $expr = $this->getSelectColumns($className, $query->getAlias(), '', $pk);
            }
            if (isset($query->query['columns'])) {
                $query->query['columns'] = array();
            }
            if (!empty($query->query['groupby']) || !empty($query->query['having'])) {
                $query->select($expr);
                if ($query->prepare()) {
                    $countQuery = new xPDOCriteria($this, "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq", $query->bindings, $query->cacheFlag);
                    $stmt = $countQuery->prepare();
                }
            } else {
                $query->select(array("COUNT(DISTINCT {$expr})"));
                $stmt = $query->prepare();
            }
            if ($stmt && $stmt->execute()) {
                $count = intval($stmt->fetchColumn());
            }
        }
        return $count;
    }
public function getCount($className, $criteria = null) {
        $count = 0;
        if ($query = $this->newQuery($className, $criteria)) {
            $stmt = null;
            $expr = '*';
            if ($pk = $this->getPK($className)) {
                if (!is_array($pk)) {
                    $pk = array($pk);
                }
                $expr = $this->getSelectColumns($className, $query->getAlias(), '', $pk);
            }
            if (isset($query->query['columns'])) {
                $query->query['columns'] = array();
            }
            if (!empty($query->query['groupby']) || !empty($query->query['having'])) {
                $query->select($expr);
                if ($query->prepare()) {
                    $countQuery = new xPDOCriteria($this, "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq", $query->bindings, $query->cacheFlag);
                    $stmt = $countQuery->prepare();
                }
            } else {
                $query->select(array("COUNT(DISTINCT {$expr})"));
                $stmt = $query->prepare();
            }
            if ($stmt && $stmt->execute()) {
                $count = intval($stmt->fetchColumn());
            }
        }
        return $count;
    }
public function getCount ( $ className , $ criteria = null ) { $ count = 0 ; if ( $ query = $ this -> newQuery ( $ className , $ criteria ) ) { $ stmt = null ; $ expr = '*' ; if ( $ pk = $ this -> getPK ( $ className ) ) { if ( ! is_array ( $ pk ) ) { $ pk = array ( $ pk ) ; } $ expr = $ this -> getSelectColumns ( $ className , $ query -> getAlias ( ) , '' , $ pk ) ; } if ( isset ( $ query -> query [ 'columns' ] ) ) { $ query -> query [ 'columns' ] = array ( ) ; } if ( ! empty ( $ query -> query [ 'groupby' ] ) || ! empty ( $ query -> query [ 'having' ] ) ) { $ query -> select ( $ expr ) ; if ( $ query -> prepare ( ) ) { $ countQuery = new xPDOCriteria ( $ this , "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq" , $ query -> bindings , $ query -> cacheFlag ) ; $ stmt = $ countQuery -> prepare ( ) ; } } else { $ query -> select ( array ( "COUNT(DISTINCT {$expr})" ) ) ; $ stmt = $ query -> prepare ( ) ; } if ( $ stmt && $ stmt -> execute ( ) ) { $ count = intval ( $ stmt -> fetchColumn ( ) ) ; } } return $ count ; }
Retrieves a count of xPDOObjects by the specified xPDOCriteria.

@param string $className Class of xPDOObject to count instances of.
@param mixed $criteria Any valid xPDOCriteria object or expression.
@return integer The number of instances found by the criteria.
Retrieves a count of xPDOObjects by the specified xPDOCriteria .