PHP 트레잇 yii\db\QueryTrait

It is supposed to be used in a class that implements the QueryInterface.
부터: 2.0
저자: Qiang Xue ([email protected])
저자: Carsten Brandt ([email protected])
파일 보기 프로젝트 열기: yiisoft/yii2

공개 프로퍼티들

프로퍼티 타입 설명
$emulateExecution whether to emulate the actual query execution, returning empty or false results.
$indexBy string | callable
$limit maximum number of records to be returned. If not set or less than 0, it means no limit.
$offset zero-based offset from where the records are to be returned. If not set or less than 0, it means starting from the beginning.
$orderBy how to sort the query results. This is used to construct the ORDER BY clause in a SQL statement. The array keys are the columns to be sorted by, and the array values are the corresponding sort directions which can be either SORT_ASC or SORT_DESC. The array may also contain [[Expression]] objects. If that is the case, the expressions will be converted into strings without any change.
$where query condition. This refers to the WHERE clause in a SQL statement. For example, ['age' => 31, 'team' => 1].

공개 메소드들

메소드 설명
addOrderBy ( string | array | yii\db\Expression $columns ) Adds additional ORDER BY columns to the query.
andFilterWhere ( array $condition ) Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
andWhere ( string | array $condition ) Adds an additional WHERE condition to the existing one.
emulateExecution ( boolean $value = true ) Sets whether to emulate query execution, preventing any interaction with data storage.
filterWhere ( array $condition ) Sets the WHERE part of the query but ignores [[isEmpty()|empty operands]].
indexBy ( string | callable $column ) Sets the [[indexBy]] property.
limit ( integer $limit ) Sets the LIMIT part of the query.
offset ( integer $offset ) Sets the OFFSET part of the query.
orFilterWhere ( array $condition ) Adds an additional WHERE condition to the existing one but ignores [[isEmpty()|empty operands]].
orWhere ( string | array $condition ) Adds an additional WHERE condition to the existing one.
orderBy ( string | array | yii\db\Expression $columns ) Sets the ORDER BY part of the query.
where ( string | array $condition ) Sets the WHERE part of the query.

보호된 메소드들

메소드 설명
filterCondition ( array $condition ) : array Removes [[isEmpty()|empty operands]] from the given query condition.
isEmpty ( mixed $value ) : boolean Returns a value indicating whether the give value is "empty".
normalizeOrderBy ( array | string | yii\db\Expression $columns ) : array Normalizes format of ORDER BY data

메소드 상세

addOrderBy() 공개 메소드

Adds additional ORDER BY columns to the query.
또한 보기: orderBy()
public addOrderBy ( string | array | yii\db\Expression $columns )
$columns string | array | yii\db\Expression the columns (and the directions) to be ordered by. Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. `['id' => SORT_ASC, 'name' => SORT_DESC]`). 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 order-by is an expression containing commas, you should always use an array to represent the order-by information. Otherwise, the method will not be able to correctly determine the order-by columns. Since version 2.0.7, an [[Expression]] object can be passed to specify the ORDER BY part explicitly in plain SQL.

andFilterWhere() 공개 메소드

The new condition and the existing one will be joined using the 'AND' operator. This method is similar to QueryTrait::andWhere. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users.
또한 보기: filterWhere()
또한 보기: orFilterWhere()
public andFilterWhere ( array $condition )
$condition array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

andWhere() 공개 메소드

The new condition and the existing one will be joined using the 'AND' operator.
또한 보기: where()
또한 보기: orWhere()
public andWhere ( string | array $condition )
$condition string | array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

emulateExecution() 공개 메소드

After this mode is enabled, methods, returning query results like [[one()]], [[all()]], [[exists()]] and so on, will return empty or false values. You should use this method in case your program logic indicates query should not return any results, like in case you set false where condition like 0=1.
부터: 2.0.11
public emulateExecution ( boolean $value = true )
$value boolean whether to prevent query execution.

filterCondition() 보호된 메소드

Removes [[isEmpty()|empty operands]] from the given query condition.
protected filterCondition ( array $condition ) : array
$condition array the original condition
리턴 array the condition with [[isEmpty()|empty operands]] removed.

filterWhere() 공개 메소드

This method is similar to QueryTrait::where. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users. The following code shows the difference between this method and QueryTrait::where: php WHERE age=:age $query->filterWhere(['name' => null, 'age' => 20]); WHERE age=:age $query->where(['age' => 20]); WHERE name IS NULL AND age=:age $query->where(['name' => null, 'age' => 20]); Note that unlike QueryTrait::where, you cannot pass binding parameters to this method.
또한 보기: where()
또한 보기: andFilterWhere()
또한 보기: orFilterWhere()
public filterWhere ( array $condition )
$condition array the conditions that should be put in the WHERE part. See [[where()]] on how to specify this parameter.

indexBy() 공개 메소드

Sets the [[indexBy]] property.
public indexBy ( string | callable $column )
$column string | callable the name of the column by which the query results should be indexed by. This can also be a callable (e.g. anonymous function) that returns the index value based on the given row data. The signature of the callable should be: ```php function ($row) { // return the index value corresponding to $row } ```

isEmpty() 보호된 메소드

The value is considered "empty", if one of the following conditions is satisfied: - it is null, - an empty string (''), - a string containing only whitespace characters, - or an empty array.
protected isEmpty ( mixed $value ) : boolean
$value mixed
리턴 boolean if the value is empty

limit() 공개 메소드

Sets the LIMIT part of the query.
public limit ( integer $limit )
$limit integer the limit. Use null or negative value to disable limit.

normalizeOrderBy() 보호된 메소드

Normalizes format of ORDER BY data
protected normalizeOrderBy ( array | string | yii\db\Expression $columns ) : array
$columns array | string | yii\db\Expression the columns value to normalize. See [[orderBy]] and [[addOrderBy]].
리턴 array

offset() 공개 메소드

Sets the OFFSET part of the query.
public offset ( integer $offset )
$offset integer the offset. Use null or negative value to disable offset.

orFilterWhere() 공개 메소드

The new condition and the existing one will be joined using the 'OR' operator. This method is similar to QueryTrait::orWhere. The main difference is that this method will remove [[isEmpty()|empty query operands]]. As a result, this method is best suited for building query conditions based on filter values entered by users.
또한 보기: filterWhere()
또한 보기: andFilterWhere()
public orFilterWhere ( array $condition )
$condition array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

orWhere() 공개 메소드

The new condition and the existing one will be joined using the 'OR' operator.
또한 보기: where()
또한 보기: andWhere()
public orWhere ( string | array $condition )
$condition string | array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.

orderBy() 공개 메소드

Sets the ORDER BY part of the query.
또한 보기: addOrderBy()
public orderBy ( string | array | yii\db\Expression $columns )
$columns string | array | yii\db\Expression the columns (and the directions) to be ordered by. Columns can be specified in either a string (e.g. `"id ASC, name DESC"`) or an array (e.g. `['id' => SORT_ASC, 'name' => SORT_DESC]`). 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 order-by is an expression containing commas, you should always use an array to represent the order-by information. Otherwise, the method will not be able to correctly determine the order-by columns. Since version 2.0.7, an [[Expression]] object can be passed to specify the ORDER BY part explicitly in plain SQL.

where() 공개 메소드

See [[QueryInterface::where()]] for detailed documentation.
또한 보기: andWhere()
또한 보기: orWhere()
public where ( string | array $condition )
$condition string | array the conditions that should be put in the WHERE part.

프로퍼티 상세

$emulateExecution 공개적으로 프로퍼티

whether to emulate the actual query execution, returning empty or false results.
또한 보기: emulateExecution()
부터: 2.0.11
public $emulateExecution

$indexBy 공개적으로 프로퍼티

public string|callable $indexBy
리턴 string | callable

$limit 공개적으로 프로퍼티

maximum number of records to be returned. If not set or less than 0, it means no limit.
public $limit

$offset 공개적으로 프로퍼티

zero-based offset from where the records are to be returned. If not set or less than 0, it means starting from the beginning.
public $offset

$orderBy 공개적으로 프로퍼티

how to sort the query results. This is used to construct the ORDER BY clause in a SQL statement. The array keys are the columns to be sorted by, and the array values are the corresponding sort directions which can be either SORT_ASC or SORT_DESC. The array may also contain [[Expression]] objects. If that is the case, the expressions will be converted into strings without any change.
public $orderBy

$where 공개적으로 프로퍼티

query condition. This refers to the WHERE clause in a SQL statement. For example, ['age' => 31, 'team' => 1].
또한 보기: where() for valid syntax on specifying this value.
public $where