src/Db/Query.php
public function count($q = '*', $db = null)
    {
        if ($this->emulateExecution) {
            return new LazyPromise(function() { return resolve(0); });
        }

        return $this->queryScalar("COUNT($q)", $db);
    }
public function count($q = '*', $db = null)
    {
        if ($this->emulateExecution) {
            return new LazyPromise(function() { return resolve(0); });
        }

        return $this->queryScalar("COUNT($q)", $db);
    }
Returns the number of records.
@param string $q the COUNT expression. Defaults to '*'.
Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression.
@param DatabaseInterface|DbConnectionGetterInterface $db the database connection used to generate the SQL statement.
If this parameter is not given (or null), the `db` application component will be used.
@return LazyPromiseInterface with int|string number of records. The result may be a string depending on the
underlying database engine and to support integer values higher than a 32bit PHP integer can handle.