db\Query groupBy()

groupBy() public method Sets the GROUP BY part of the query. See also addGroupBy(). public $this groupBy ( $columns )$columns string|array|yii\db\Expression The columns to be grouped by. Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression). Note that if your group-by is an expression containing comma

db\Query from()

from() public method Sets the FROM part of the query. public $this from ( $tables )$tables string|array The table(s) to be selected from. This can be either a string (e.g. 'user') or an array (e.g. ['user', 'profile']) specifying one or several table names. Table names can contain schema prefixes (e.g. 'public.user') and/or table aliases (e.g. 'user u'). The method will automatically quote the table names unless it contains some parenthesis (which means the table is given as a sub-quer

db\Query exists()

exists() public method Returns a value indicating whether the query result contains any row of data. public boolean exists ( $db = null )$db yii\db\Connection The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used. return boolean Whether the query result contains any row of data.

db\Query each()

each() public method Starts a batch query and retrieves data row by row. This method is similar to batch() except that in each iteration of the result, only one row of data is returned. For example, $query = (new Query)->from('user'); foreach ($query->each() as $row) { } public yii\db\BatchQueryResult each ( $batchSize = 100, $db = null )$batchSize integer The number of records to be fetched in each batch. $db yii\db\Connection The database connection. If not set, the "db" appli

db\Query distinct()

distinct() public method Sets the value indicating whether to SELECT DISTINCT or not. public $this distinct ( $value = true )$value boolean Whether to SELECT DISTINCT or not. return $this The query object itself

db\Query createCommand()

createCommand() public method Creates a DB command that can be used to execute this query. public yii\db\Command createCommand ( $db = null )$db yii\db\Connection The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used. return yii\db\Command The created DB command instance.

db\Query create()

create() public static method Creates a new Query object and copies its property values from an existing one. The properties being copies are the ones to be used by query builders. public static yii\db\Query create ( $from )$from yii\db\Query The source query object return yii\db\Query The new Query object

db\Query count()

count() public method Returns the number of records. public integer|string count ( $q = '*', $db = null )$q string The COUNT expression. Defaults to '*'. Make sure you properly quote column names in the expression. $db yii\db\Connection 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 integer|string Number of records. The result may be a string depending on the underlying database

db\Query column()

column() public method Executes the query and returns the first column of the result. public array column ( $db = null )$db yii\db\Connection The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used. return array The first column of the query result. An empty array is returned if the query results in nothing.

db\Query batch()

batch() public method Starts a batch query. A batch query supports fetching data in batches, which can keep the memory usage under a limit. This method will return a yii\db\BatchQueryResult object which implements the Iterator interface and can be traversed to retrieve the data in batches. For example, $query = (new Query)->from('user'); foreach ($query->batch() as $rows) { // $rows is an array of 100 or fewer rows from user table } public yii\db\BatchQueryResult batch ( $batch