PHP Класс yii\db\QueryBuilder

SQL statements are created from Query objects using the QueryBuilder::build-method. QueryBuilder is also used by Command to build SQL statements such as INSERT, UPDATE, DELETE, CREATE TABLE. For more details and usage information on QueryBuilder, see the guide article on query builders.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Object
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$db the database connection.
$separator the separator between different fragments of a SQL statement. Defaults to an empty space. This is mainly used by QueryBuilder::build when generating a SQL statement.
$typeMap the abstract column types mapped to physical column types. This is mainly used to support creating/modifying tables using DB-independent data type specifications. Child classes should override this property to declare supported type mappings.

Защищенные свойства (Protected)

Свойство Тип Описание
$conditionBuilders map of query condition to builder methods. These methods are used by [[buildCondition]] to build SQL conditions from array syntax.

Открытые методы

Метод Описание
__construct ( Connection $connection, array $config = [] ) Constructor.
addColumn ( string $table, string $column, string $type ) : string Builds a SQL statement for adding a new DB column.
addCommentOnColumn ( string $table, string $column, string $comment ) : string Builds a SQL command for adding comment to column
addCommentOnTable ( string $table, string $comment ) : string Builds a SQL command for adding comment to table
addForeignKey ( string $name, string $table, string | array $columns, string $refTable, string | array $refColumns, string $delete = null, string $update = null ) : string Builds a SQL statement for adding a foreign key constraint to an existing table.
addPrimaryKey ( string $name, string $table, string | array $columns ) : string Builds a SQL statement for adding a primary key constraint to an existing table.
alterColumn ( string $table, string $column, string $type ) : string Builds a SQL statement for changing the definition of a column.
batchInsert ( string $table, array $columns, array $rows ) : string Generates a batch INSERT SQL statement.
build ( Query $query, array $params = [] ) : array Generates a SELECT SQL statement from a Query object.
buildAndCondition ( string $operator, array $operands, array &$params ) : string Connects two or more SQL expressions with the AND or OR operator.
buildBetweenCondition ( string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the BETWEEN operator.
buildColumns ( string | array $columns ) : string Processes columns and properly quotes them if necessary.
buildCondition ( string | array | yii\db\Expression $condition, array &$params ) : string Parses the condition specification and generates the corresponding SQL expression.
buildExistsCondition ( string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the EXISTS operator.
buildFrom ( array $tables, array &$params ) : string
buildGroupBy ( array $columns ) : string
buildHashCondition ( array $condition, array &$params ) : string Creates a condition based on column-value pairs.
buildHaving ( string | array $condition, array &$params ) : string
buildInCondition ( string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the IN operator.
buildJoin ( array $joins, array &$params ) : string
buildLikeCondition ( string $operator, array $operands, array &$params ) : string Creates an SQL expressions with the LIKE operator.
buildLimit ( integer $limit, integer $offset ) : string
buildNotCondition ( string $operator, array $operands, array &$params ) : string Inverts an SQL expressions with NOT operator.
buildOrderBy ( array $columns ) : string
buildOrderByAndLimit ( string $sql, array $orderBy, integer $limit, integer $offset ) : string Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
buildSelect ( array $columns, array &$params, boolean $distinct = false, string $selectOption = null ) : string
buildSimpleCondition ( string $operator, array $operands, array &$params ) : string Creates an SQL expressions like "column" operator value.
buildUnion ( array $unions, array &$params ) : string
buildWhere ( string | array $condition, array &$params ) : string
checkIntegrity ( boolean $check = true, string $schema = '', string $table = '' ) : string Builds a SQL statement for enabling or disabling integrity check.
createIndex ( string $name, string $table, string | array $columns, boolean $unique = false ) : string Builds a SQL statement for creating a new index.
createTable ( string $table, array $columns, string $options = null ) : string Builds a SQL statement for creating a new DB table.
delete ( string $table, array | string $condition, array &$params ) : string Creates a DELETE SQL statement.
dropColumn ( string $table, string $column ) : string Builds a SQL statement for dropping a DB column.
dropCommentFromColumn ( string $table, string $column ) : string Builds a SQL command for adding comment to column
dropCommentFromTable ( string $table ) : string Builds a SQL command for adding comment to table
dropForeignKey ( string $name, string $table ) : string Builds a SQL statement for dropping a foreign key constraint.
dropIndex ( string $name, string $table ) : string Builds a SQL statement for dropping an index.
dropPrimaryKey ( string $name, string $table ) : string Builds a SQL statement for removing a primary key constraint to an existing table.
dropTable ( string $table ) : string Builds a SQL statement for dropping a DB table.
getColumnType ( string | ColumnSchemaBuilder $type ) : string Converts an abstract column type into a physical column type.
insert ( string $table, array $columns, array &$params ) : string Creates an INSERT SQL statement.
renameColumn ( string $table, string $oldName, string $newName ) : string Builds a SQL statement for renaming a column.
renameTable ( string $oldName, string $newName ) : string Builds a SQL statement for renaming a DB table.
resetSequence ( string $table, array | string $value = null ) : string Creates a SQL statement for resetting the sequence value of a table's primary key.
selectExists ( string $rawSql ) : string Creates a SELECT EXISTS() SQL statement.
truncateTable ( string $table ) : string Builds a SQL statement for truncating a DB table.
update ( string $table, array $columns, array | string $condition, array &$params ) : string Creates an UPDATE SQL statement.

Защищенные методы

Метод Описание
buildCompositeInCondition ( string $operator, array | Traversable $columns, array $values, array &$params ) : string Builds SQL for IN condition
buildSubqueryInCondition ( string $operator, array $columns, Query $values, array &$params ) : string Builds SQL for IN condition
hasLimit ( mixed $limit ) : boolean Checks to see if the given limit is effective.
hasOffset ( mixed $offset ) : boolean Checks to see if the given offset is effective.

Приватные методы

Метод Описание
quoteTableNames ( array $tables, array &$params ) : array Quotes table names passed

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( Connection $connection, array $config = [] )
$connection Connection the database connection.
$config array name-value pairs that will be used to initialize the object properties

addColumn() публичный Метод

Builds a SQL statement for adding a new DB column.
public addColumn ( string $table, string $column, string $type ) : string
$table string the table that the new column will be added to. The table name will be properly quoted by the method.
$column string the name of the new column. The name will be properly quoted by the method.
$type string the column type. The [[getColumnType()]] method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
Результат string the SQL statement for adding a new column.

addCommentOnColumn() публичный Метод

Builds a SQL command for adding comment to column
С версии: 2.0.8
public addCommentOnColumn ( string $table, string $column, string $comment ) : string
$table string the table whose column is to be commented. The table name will be properly quoted by the method.
$column string the name of the column to be commented. The column name will be properly quoted by the method.
$comment string the text of the comment to be added. The comment will be properly quoted by the method.
Результат string the SQL statement for adding comment on column

addCommentOnTable() публичный Метод

Builds a SQL command for adding comment to table
С версии: 2.0.8
public addCommentOnTable ( string $table, string $comment ) : string
$table string the table whose column is to be commented. The table name will be properly quoted by the method.
$comment string the text of the comment to be added. The comment will be properly quoted by the method.
Результат string the SQL statement for adding comment on table

addForeignKey() публичный Метод

The method will properly quote the table and column names.
public addForeignKey ( string $name, string $table, string | array $columns, string $refTable, string | array $refColumns, string $delete = null, string $update = null ) : string
$name string the name of the foreign key constraint.
$table string the table that the foreign key constraint will be added to.
$columns string | array the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array to represent them.
$refTable string the table that the foreign key references to.
$refColumns string | array the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or use an array to represent them.
$delete string the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
$update string the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
Результат string the SQL statement for adding a foreign key constraint to an existing table.

addPrimaryKey() публичный Метод

Builds a SQL statement for adding a primary key constraint to an existing table.
public addPrimaryKey ( string $name, string $table, string | array $columns ) : string
$name string the name of the primary key constraint.
$table string the table that the primary key constraint will be added to.
$columns string | array comma separated string or array of columns that the primary key will consist of.
Результат string the SQL statement for adding a primary key constraint to an existing table.

alterColumn() публичный Метод

Builds a SQL statement for changing the definition of a column.
public alterColumn ( string $table, string $column, string $type ) : string
$table string the table whose column is to be changed. The table name will be properly quoted by the method.
$column string the name of the column to be changed. The name will be properly quoted by the method.
$type string the new column type. The [[getColumnType()]] method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
Результат string the SQL statement for changing the definition of a column.

batchInsert() публичный Метод

For example, php $sql = $queryBuilder->batchInsert('user', ['name', 'age'], [ ['Tom', 30], ['Jane', 20], ['Linda', 25], ]); Note that the values in each row must match the corresponding column names. The method will properly escape the column names, and quote the values to be inserted.
public batchInsert ( string $table, array $columns, array $rows ) : string
$table string the table that new rows will be inserted into.
$columns array the column names
$rows array the rows to be batch inserted into the table
Результат string the batch INSERT SQL statement

build() публичный Метод

Generates a SELECT SQL statement from a Query object.
public build ( Query $query, array $params = [] ) : array
$query Query the [[Query]] object from which the SQL statement will be generated.
$params array the parameters to be bound to the generated SQL statement. These parameters will be included in the result with the additional parameters generated during the query building process.
Результат array the generated SQL statement (the first array element) and the corresponding parameters to be bound to the SQL statement (the second array element). The parameters returned include those provided in `$params`.

buildAndCondition() публичный Метод

Connects two or more SQL expressions with the AND or OR operator.
public buildAndCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use for connecting the given operands
$operands array the SQL expressions to connect.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildBetweenCondition() публичный Метод

Creates an SQL expressions with the BETWEEN operator.
public buildBetweenCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use (e.g. `BETWEEN` or `NOT BETWEEN`)
$operands array the first operand is the column name. The second and third operands describe the interval that column value should be in.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildColumns() публичный Метод

It will join all columns into a string with comma as separators.
public buildColumns ( string | array $columns ) : string
$columns string | array the columns to be processed
Результат string the processing result

buildCompositeInCondition() защищенный Метод

Builds SQL for IN condition
protected buildCompositeInCondition ( string $operator, array | Traversable $columns, array $values, array &$params ) : string
$operator string
$columns array | Traversable
$values array
$params array
Результат string SQL

buildCondition() публичный Метод

Parses the condition specification and generates the corresponding SQL expression.
public buildCondition ( string | array | yii\db\Expression $condition, array &$params ) : string
$condition string | array | yii\db\Expression the condition specification. Please refer to [[Query::where()]] on how to specify a condition.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildExistsCondition() публичный Метод

Creates an SQL expressions with the EXISTS operator.
public buildExistsCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use (e.g. `EXISTS` or `NOT EXISTS`)
$operands array contains only one element which is a [[Query]] object representing the sub-query.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildFrom() публичный Метод

public buildFrom ( array $tables, array &$params ) : string
$tables array
$params array the binding parameters to be populated
Результат string the FROM clause built from [[Query::$from]].

buildGroupBy() публичный Метод

public buildGroupBy ( array $columns ) : string
$columns array
Результат string the GROUP BY clause

buildHashCondition() публичный Метод

Creates a condition based on column-value pairs.
public buildHashCondition ( array $condition, array &$params ) : string
$condition array the condition specification.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildHaving() публичный Метод

public buildHaving ( string | array $condition, array &$params ) : string
$condition string | array
$params array the binding parameters to be populated
Результат string the HAVING clause built from [[Query::$having]].

buildInCondition() публичный Метод

Creates an SQL expressions with the IN operator.
public buildInCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use (e.g. `IN` or `NOT IN`)
$operands array the first operand is the column name. If it is an array a composite IN condition will be generated. The second operand is an array of values that column value should be among. If it is an empty array the generated expression will be a `false` value if operator is `IN` and empty if operator is `NOT IN`.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildJoin() публичный Метод

public buildJoin ( array $joins, array &$params ) : string
$joins array
$params array the binding parameters to be populated
Результат string the JOIN clause built from [[Query::$join]].

buildLikeCondition() публичный Метод

Creates an SQL expressions with the LIKE operator.
public buildLikeCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use (e.g. `LIKE`, `NOT LIKE`, `OR LIKE` or `OR NOT LIKE`)
$operands array an array of two or three operands - The first operand is the column name. - The second operand is a single value or an array of values that column value should be compared with. If it is an empty array the generated expression will be a `false` value if operator is `LIKE` or `OR LIKE`, and empty if operator is `NOT LIKE` or `OR NOT LIKE`. - An optional third operand can also be provided to specify how to escape special characters in the value(s). The operand should be an array of mappings from the special characters to their escaped counterparts. If this operand is not provided, a default escape mapping will be used. You may use `false` or an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildLimit() публичный Метод

public buildLimit ( integer $limit, integer $offset ) : string
$limit integer
$offset integer
Результат string the LIMIT and OFFSET clauses

buildNotCondition() публичный Метод

Inverts an SQL expressions with NOT operator.
public buildNotCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use for connecting the given operands
$operands array the SQL expressions to connect.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildOrderBy() публичный Метод

public buildOrderBy ( array $columns ) : string
$columns array
Результат string the ORDER BY clause built from [[Query::$orderBy]].

buildOrderByAndLimit() публичный Метод

Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
public buildOrderByAndLimit ( string $sql, array $orderBy, integer $limit, integer $offset ) : string
$sql string the existing SQL (without ORDER BY/LIMIT/OFFSET)
$orderBy array the order by columns. See [[Query::orderBy]] for more details on how to specify this parameter.
$limit integer the limit number. See [[Query::limit]] for more details.
$offset integer the offset number. See [[Query::offset]] for more details.
Результат string the SQL completed with ORDER BY/LIMIT/OFFSET (if any)

buildSelect() публичный Метод

public buildSelect ( array $columns, array &$params, boolean $distinct = false, string $selectOption = null ) : string
$columns array
$params array the binding parameters to be populated
$distinct boolean
$selectOption string
Результат string the SELECT clause built from [[Query::$select]].

buildSimpleCondition() публичный Метод

Creates an SQL expressions like "column" operator value.
public buildSimpleCondition ( string $operator, array $operands, array &$params ) : string
$operator string the operator to use. Anything could be used e.g. `>`, `<=`, etc.
$operands array contains two column names.
$params array the binding parameters to be populated
Результат string the generated SQL expression

buildSubqueryInCondition() защищенный Метод

Builds SQL for IN condition
protected buildSubqueryInCondition ( string $operator, array $columns, Query $values, array &$params ) : string
$operator string
$columns array
$values Query
$params array
Результат string SQL

buildUnion() публичный Метод

public buildUnion ( array $unions, array &$params ) : string
$unions array
$params array the binding parameters to be populated
Результат string the UNION clause built from [[Query::$union]].

buildWhere() публичный Метод

public buildWhere ( string | array $condition, array &$params ) : string
$condition string | array
$params array the binding parameters to be populated
Результат string the WHERE clause built from [[Query::$where]].

checkIntegrity() публичный Метод

Builds a SQL statement for enabling or disabling integrity check.
public checkIntegrity ( boolean $check = true, string $schema = '', string $table = '' ) : string
$check boolean whether to turn on or off the integrity check.
$schema string the schema of the tables. Defaults to empty string, meaning the current or default schema.
$table string the table name. Defaults to empty string, meaning that no table will be changed.
Результат string the SQL statement for checking integrity

createIndex() публичный Метод

Builds a SQL statement for creating a new index.
public createIndex ( string $name, string $table, string | array $columns, boolean $unique = false ) : string
$name string the name of the index. The name will be properly quoted by the method.
$table string the table that the new index will be created for. The table name will be properly quoted by the method.
$columns string | array the column(s) that should be included in the index. If there are multiple columns, separate them with commas or use an array to represent them. Each column name will be properly quoted by the method, unless a parenthesis is found in the name.
$unique boolean whether to add UNIQUE constraint on the created index.
Результат string the SQL statement for creating a new index.

createTable() публичный Метод

The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name stands for a column name which will be properly quoted by the method, and definition stands for the column type which can contain an abstract DB type. The QueryBuilder::getColumnType method will be invoked to convert any abstract type into a physical one. If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly inserted into the generated SQL. For example, php $sql = $queryBuilder->createTable('user', [ 'id' => 'pk', 'name' => 'string', 'age' => 'integer', ]);
public createTable ( string $table, array $columns, string $options = null ) : string
$table string the name of the table to be created. The name will be properly quoted by the method.
$columns array the columns (name => definition) in the new table.
$options string additional SQL fragment that will be appended to the generated SQL.
Результат string the SQL statement for creating a new DB table.

delete() публичный Метод

For example, php $sql = $queryBuilder->delete('user', 'status = 0'); The method will properly escape the table and column names.
public delete ( string $table, array | string $condition, array &$params ) : string
$table string the table where the data will be deleted from.
$condition array | string the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition.
$params array the binding parameters that will be modified by this method so that they can be bound to the DB command later.
Результат string the DELETE SQL

dropColumn() публичный Метод

Builds a SQL statement for dropping a DB column.
public dropColumn ( string $table, string $column ) : string
$table string the table whose column is to be dropped. The name will be properly quoted by the method.
$column string the name of the column to be dropped. The name will be properly quoted by the method.
Результат string the SQL statement for dropping a DB column.

dropCommentFromColumn() публичный Метод

Builds a SQL command for adding comment to column
С версии: 2.0.8
public dropCommentFromColumn ( string $table, string $column ) : string
$table string the table whose column is to be commented. The table name will be properly quoted by the method.
$column string the name of the column to be commented. The column name will be properly quoted by the method.
Результат string the SQL statement for adding comment on column

dropCommentFromTable() публичный Метод

Builds a SQL command for adding comment to table
С версии: 2.0.8
public dropCommentFromTable ( string $table ) : string
$table string the table whose column is to be commented. The table name will be properly quoted by the method.
Результат string the SQL statement for adding comment on column

dropForeignKey() публичный Метод

Builds a SQL statement for dropping a foreign key constraint.
public dropForeignKey ( string $name, string $table ) : string
$name string the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
$table string the table whose foreign is to be dropped. The name will be properly quoted by the method.
Результат string the SQL statement for dropping a foreign key constraint.

dropIndex() публичный Метод

Builds a SQL statement for dropping an index.
public dropIndex ( string $name, string $table ) : string
$name string the name of the index to be dropped. The name will be properly quoted by the method.
$table string the table whose index is to be dropped. The name will be properly quoted by the method.
Результат string the SQL statement for dropping an index.

dropPrimaryKey() публичный Метод

Builds a SQL statement for removing a primary key constraint to an existing table.
public dropPrimaryKey ( string $name, string $table ) : string
$name string the name of the primary key constraint to be removed.
$table string the table that the primary key constraint will be removed from.
Результат string the SQL statement for removing a primary key constraint from an existing table.

dropTable() публичный Метод

Builds a SQL statement for dropping a DB table.
public dropTable ( string $table ) : string
$table string the table to be dropped. The name will be properly quoted by the method.
Результат string the SQL statement for dropping a DB table.

getColumnType() публичный Метод

The conversion is done using the type map specified in [[typeMap]]. The following abstract column types are supported (using MySQL as an example to explain the corresponding physical types): - pk: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY" - bigpk: an auto-incremental primary key type, will be converted into "bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY" - unsignedpk: an unsigned auto-incremental primary key type, will be converted into "int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY" - char: char type, will be converted into "char(1)" - string: string type, will be converted into "varchar(255)" - text: a long string type, will be converted into "text" - smallint: a small integer type, will be converted into "smallint(6)" - integer: integer type, will be converted into "int(11)" - bigint: a big integer type, will be converted into "bigint(20)" - boolean: boolean type, will be converted into "tinyint(1)" - float: float number type, will be converted into "float" - decimal: decimal number type, will be converted into "decimal" - datetime: datetime type, will be converted into "datetime" - timestamp: timestamp type, will be converted into "timestamp" - time: time type, will be converted into "time" - date: date type, will be converted into "date" - money: money type, will be converted into "decimal(19,4)" - binary: binary data type, will be converted into "blob" If the abstract type contains two or more parts separated by spaces (e.g. "string NOT NULL"), then only the first part will be converted, and the rest of the parts will be appended to the converted result. For example, 'string NOT NULL' is converted to 'varchar(255) NOT NULL'. For some of the abstract types you can also specify a length or precision constraint by appending it in round brackets directly to the type. For example string(32) will be converted into "varchar(32)" on a MySQL database. If the underlying DBMS does not support these kind of constraints for a type it will be ignored. If a type cannot be found in [[typeMap]], it will be returned without any change.
public getColumnType ( string | ColumnSchemaBuilder $type ) : string
$type string | ColumnSchemaBuilder abstract column type
Результат string physical column type.

hasLimit() защищенный Метод

Checks to see if the given limit is effective.
protected hasLimit ( mixed $limit ) : boolean
$limit mixed the given limit
Результат boolean whether the limit is effective

hasOffset() защищенный Метод

Checks to see if the given offset is effective.
protected hasOffset ( mixed $offset ) : boolean
$offset mixed the given offset
Результат boolean whether the offset is effective

insert() публичный Метод

For example, php $sql = $queryBuilder->insert('user', [ 'name' => 'Sam', 'age' => 30, ], $params); The method will properly escape the table and column names.
public insert ( string $table, array $columns, array &$params ) : string
$table string the table that new rows will be inserted into.
$columns array the column data (name => value) to be inserted into the table.
$params array the binding parameters that will be generated by this method. They should be bound to the DB command later.
Результат string the INSERT SQL

renameColumn() публичный Метод

Builds a SQL statement for renaming a column.
public renameColumn ( string $table, string $oldName, string $newName ) : string
$table string the table whose column is to be renamed. The name will be properly quoted by the method.
$oldName string the old name of the column. The name will be properly quoted by the method.
$newName string the new name of the column. The name will be properly quoted by the method.
Результат string the SQL statement for renaming a DB column.

renameTable() публичный Метод

Builds a SQL statement for renaming a DB table.
public renameTable ( string $oldName, string $newName ) : string
$oldName string the table to be renamed. The name will be properly quoted by the method.
$newName string the new table name. The name will be properly quoted by the method.
Результат string the SQL statement for renaming a DB table.

resetSequence() публичный Метод

The sequence will be reset such that the primary key of the next new row inserted will have the specified value or 1.
public resetSequence ( string $table, array | string $value = null ) : string
$table string the name of the table whose primary key sequence will be reset
$value array | string the value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have a value 1.
Результат string the SQL statement for resetting sequence

selectExists() публичный Метод

Creates a SELECT EXISTS() SQL statement.
С версии: 2.0.8
public selectExists ( string $rawSql ) : string
$rawSql string the subquery in a raw form to select from.
Результат string the SELECT EXISTS() SQL statement.

truncateTable() публичный Метод

Builds a SQL statement for truncating a DB table.
public truncateTable ( string $table ) : string
$table string the table to be truncated. The name will be properly quoted by the method.
Результат string the SQL statement for truncating a DB table.

update() публичный Метод

For example, php $params = []; $sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params); The method will properly escape the table and column names.
public update ( string $table, array $columns, array | string $condition, array &$params ) : string
$table string the table to be updated.
$columns array the column data (name => value) to be updated.
$condition array | string the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition.
$params array the binding parameters that will be modified by this method so that they can be bound to the DB command later.
Результат string the UPDATE SQL

Описание свойств

$conditionBuilders защищенное свойство

map of query condition to builder methods. These methods are used by [[buildCondition]] to build SQL conditions from array syntax.
protected $conditionBuilders

$db публичное свойство

the database connection.
public $db

$separator публичное свойство

the separator between different fragments of a SQL statement. Defaults to an empty space. This is mainly used by QueryBuilder::build when generating a SQL statement.
public $separator

$typeMap публичное свойство

the abstract column types mapped to physical column types. This is mainly used to support creating/modifying tables using DB-independent data type specifications. Child classes should override this property to declare supported type mappings.
public $typeMap