db\Query select()

select() public method

Sets the SELECT part of the query.

public $this select ( $columns, $option = null )
$columns string|array|yii\db\Expression

The columns to be selected. Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']). Columns can be prefixed with table names (e.g. "user.id") and/or contain column aliases (e.g. "user.id AS user_id"). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression). A DB expression may also be passed in form of an yii\db\Expression object.

Note that if you are selecting an expression like CONCAT(first_name, ' ', last_name), you should use an array to specify the columns. Otherwise, the expression may be incorrectly split into several parts.

When the columns are specified as an array, you may also use array keys as the column aliases (if a column does not need alias, do not use a string key).

Starting from version 2.0.1, you may also select sub-queries as columns by specifying each such column as a Query instance representing the sub-query.

$option string

Additional option that should be appended to the 'SELECT' keyword. For example, in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.

return $this

The query object itself

doc_Yii
2016-10-30 16:59:05
Comments
Leave a Comment

Please login to continue.