Interface Yiisoft\Db\QueryBuilder\QueryBuilderInterface
Defines the common interface to be implemented by query builder classes.
A query builder is mainly responsible for creating SQL statements based on specifications given in a {@see \Yiisoft\Db\QueryBuilder\QueryInterface} object.
A query builder should also support creating SQL statements for DBMS-specific features such as creating indexes, adding foreign keys, etc. through the methods defined in {@see \Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface}, {@see \Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface} and {@see \Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| addCheck() | Creates an SQL command for adding a check constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addColumn() | Builds an SQL statement for adding a new DB column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addCommentOnColumn() | Builds an SQL command for adding comment to column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addCommentOnTable() | Builds an SQL command for adding comment to the table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addDefaultValue() | Creates an SQL command for adding a default value constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addForeignKey() | Builds an SQL statement for adding a foreign key constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addPrimaryKey() | Builds an SQL statement for adding a primary key constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| addUnique() | Creates an SQL command for adding a unique constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| alterColumn() | Builds an SQL statement for changing the definition of a column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| bindParam() | Helper method to add $value to $params array using {@see PARAM_PREFIX}. |
Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| build() | Generates a SELECT SQL statement from a {@see Query} object. |
Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildColumnDefinition() | Builds column definition based on given column instance. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| buildColumns() | Processes columns and quotes them if necessary. | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildCondition() | Parses the condition specification and generates the corresponding SQL expression. | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildExpression() | Builds given $expression. | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildFor() | Builds a SQL for FOR clause. |
Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildFrom() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildGroupBy() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildHaving() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildJoin() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildLimit() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildOrderBy() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildOrderByAndLimit() | Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. |
Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| buildSelect() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildUnion() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildValue() | Securely converts PHP values to their SQL representations with using bind parameters where necessary:
- array values are converted to JSON or SQL array expressions;
- bool values are converted to TRUE or FALSE or other DBMS-specific boolean representations;
- float and int values are converted to their string representations;
- null values are converted to NULL;
- object values are converted to their SQL representation based on their type;
- resource values are bound as LOB parameters;
- closed resource throw an {@see InvalidArgumentException};
- string values are bound as string parameters;
- other values are bound as parameters. |
Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| buildWhere() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| buildWithQueries() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| checkIntegrity() | Builds an SQL statement for enabling or disabling integrity check. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| createConditionFromArray() | Transforms one condition defined in array format (as described in {@see Query::where()} to instance of {@see ConditionInterface}). | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| createIndex() | Builds an SQL statement for creating a new index. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| createTable() | Builds an SQL statement for creating a new DB table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| createView() | Creates an SQL View. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| delete() | Creates a DELETE SQL statement. |
Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| dropCheck() | Creates an SQL command for dropping a check constraint. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropColumn() | Builds an SQL statement for dropping a DB column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropCommentFromColumn() | Builds an SQL command for dropping comment to column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropCommentFromTable() | Builds an SQL command for dropping comment to the table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropDefaultValue() | Creates an SQL command for dropping a default value constraint. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropForeignKey() | Builds an SQL statement for dropping a foreign key constraint. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropIndex() | Builds an SQL statement for dropping an index. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropPrimaryKey() | Builds an SQL statement for removing a primary key constraint to an existing table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropTable() | Builds an SQL statement for dropping a DB table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropUnique() | Creates an SQL command for dropping a unique constraint. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| dropView() | Drops an SQL View. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| getColumnDefinitionBuilder() | Returns the column definition builder for the current DBMS. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| getColumnFactory() | Returns the column factory for creating column instances. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| getExpressionBuilder() | Gets an object of {@see ExpressionBuilderInterface} that's suitable for $expression. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| getQuoter() | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | |
| getServerInfo() | Returns {@see ServerInfoInterface} instance that provides information about the database server. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| insert() | Creates an INSERT SQL statement. |
Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| insertBatch() | Generates a batch INSERT SQL statement. |
Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| insertReturningPks() | Creates an INSERT SQL statement with returning inserted primary key values. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| isTypecastingEnabled() | Returns whether type casting is enabled for the query builder. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| prepareParam() | Converts a {@see Param} object to its SQL representation and quotes it if necessary. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| prepareValue() | Converts a value to its SQL representation and quotes it if necessary. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| renameColumn() | Builds an SQL statement for renaming a column. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| renameTable() | Builds an SQL statement for renaming a DB table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| replacePlaceholders() | Replaces placeholders in the SQL string with the corresponding values. | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
| resetSequence() | Creates an SQL statement for resetting the sequence value of a table's primary key. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| selectExists() | Creates a SELECT EXISTS() SQL statement. |
Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| setConditionClasses() | Setter for {@see AbstractDQLQueryBuilder::conditionClasses} property. | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| setExpressionBuilders() | Setter for {@see AbstractDQLQueryBuilder::expressionBuilders} property. | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface |
| setSeparator() | Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface | |
| truncateTable() | Builds an SQL statement for truncating a DB table. | Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface |
| update() | Creates an UPDATE SQL statement. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| upsert() | Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| upsertReturning() | Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do, with returning values from the specified columns. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
| withTypecasting() | Clones the current instance and sets whether type casting is required for the query builder. | Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface |
Method Details
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCheck()
Creates an SQL command for adding a check constraint to an existing table.
| public abstract string addCheck ( string $table, string $name, string $expression ) | ||
| $table | string |
The table to add the check constraint to. |
| $name | string |
The name of the check constraint. |
| $expression | string |
The SQL of the |
| return | string |
The SQL statement for adding a check constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addCheck(string $table, string $name, string $expression): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addColumn()
Builds an SQL statement for adding a new DB column.
| public abstract string addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string |
The table to add the new column will to. |
| $column | string |
The name of the new column. |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. |
| return | string |
The SQL statement for adding a new column. Note: The method will quote the |
|---|---|---|
public function addColumn(string $table, string $column, ColumnInterface|string $type): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCommentOnColumn()
Builds an SQL command for adding comment to column.
| public abstract string addCommentOnColumn ( string $table, string $column, string $comment ) | ||
| $table | string |
The table whose column to be comment. |
| $column | string |
The name of the column to comment. |
| $comment | string |
The text of the comment to add. |
| return | string |
The SQL statement for adding comment on column. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
public function addCommentOnColumn(string $table, string $column, string $comment): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCommentOnTable()
Builds an SQL command for adding comment to the table.
| public abstract string addCommentOnTable ( string $table, string $comment ) | ||
| $table | string |
The table whose column is to comment. |
| $comment | string |
The text of the comment to add. |
| return | string |
The SQL statement for adding comment on the table. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
public function addCommentOnTable(string $table, string $comment): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addDefaultValue()
Creates an SQL command for adding a default value constraint to an existing table.
| public abstract string addDefaultValue ( string $table, string $name, string $column, mixed $value ) | ||
| $table | string |
The table toi add the default value constraint to. |
| $name | string |
The name of the default value constraint. |
| $column | string |
The name of the column to add constraint on. |
| $value | mixed |
The default value to set for the column. |
| return | string |
The SQL statement for adding a default value constraint to an existing table. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function addDefaultValue(string $table, string $name, string $column, mixed $value): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addForeignKey()
Builds an SQL statement for adding a foreign key constraint to an existing table.
The method will quote the name, table, referenceTable parameters before using them in the generated SQL.
| public abstract string addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete = null, string|null $update = null ) | ||
| $table | string |
The table to add the foreign key constraint will to. |
| $name | string |
The name of the foreign key constraint. |
| $columns | array|string |
The name of the column to add the constraint will on. If there are many columns, separate them with commas or use an array to represent them. |
| $referenceTable | string |
The table that the foreign key references to. |
| $referenceColumns | array|string |
The name of the column that the foreign key references to. If there are many columns, separate them with commas or use an array to represent them. |
| $delete | string|null |
The |
| $update | string|null |
The |
| return | string |
The SQL statement for adding a foreign key constraint to an existing table. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function addForeignKey(
string $table,
string $name,
array|string $columns,
string $referenceTable,
array|string $referenceColumns,
?string $delete = null,
?string $update = null,
): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addPrimaryKey()
Builds an SQL statement for adding a primary key constraint to an existing table.
| public abstract string addPrimaryKey ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The table to add the primary key constraint will to. |
| $name | string |
The name of the primary key constraint. |
| $columns | string|string[] |
Comma separated string or array of columns that the primary key will consist of. |
| return | string |
The SQL statement for adding a primary key constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addPrimaryKey(string $table, string $name, array|string $columns): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addUnique()
Creates an SQL command for adding a unique constraint to an existing table.
| public abstract string addUnique ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The table to add the unique constraint to. |
| $name | string |
The name of the unique constraint. |
| $columns | string|string[] |
The name of the column to add the constraint on. If there are many columns, separate them with commas. |
| return | string |
The SQL statement for adding a unique constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addUnique(string $table, string $name, array|string $columns): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::alterColumn()
Builds an SQL statement for changing the definition of a column.
| public abstract string alterColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string |
The table whose column is to change. |
| $column | string |
The name of the column to change. |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. |
| return | string |
The SQL statement for changing the definition of a column. Note: The method will quote the |
|---|---|---|
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string;
Helper method to add $value to $params array using {@see PARAM_PREFIX}.
| public abstract string bindParam ( mixed $value, array &$params = [] ) | ||
| $value | mixed | |
| $params | array |
Passed by reference. |
| return | string |
The placeholder name in $params array. |
|---|---|---|
public function bindParam(mixed $value, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::build()
Generates a SELECT SQL statement from a {@see Query} object.
| public abstract array build ( Yiisoft\Db\Query\QueryInterface $query, array $params = [] ) | ||
| $query | Yiisoft\Db\Query\QueryInterface |
The {@see \Yiisoft\Db\Query\Query} object from which the SQL statement will generated. |
| $params | array |
The parameters to bind to the generated SQL statement. These parameters will be included in the result, with the more parameters generated during the query building process. |
| return | array |
The generated SQL statement (the first array element) and the corresponding parameters to bind
to the SQL statement (the second array element). The parameters returned include those provided in |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function build(QueryInterface $query, array $params = []): array;
Builds column definition based on given column instance.
| public abstract string buildColumnDefinition ( Yiisoft\Db\Schema\Column\ColumnInterface|string $column ) | ||
| $column | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column instance or string column definition which should be converted into a database string representation. |
| return | string |
The SQL column definition. |
|---|---|---|
public function buildColumnDefinition(ColumnInterface|string $column): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildColumns()
Processes columns and quotes them if necessary.
It will join all columns into a string with comma as separators.
| public abstract string buildColumns ( array|string $columns ) | ||
| $columns | array|string |
The columns to process. |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
|---|---|---|
public function buildColumns(array|string $columns): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildCondition()
Parses the condition specification and generates the corresponding SQL expression.
| public abstract string buildCondition ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] ) | ||
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string|null |
The condition specification. Please refer to {@see \Yiisoft\Db\Query\Query::where()} on how to specify a condition. |
| $params | array |
The binding parameters to populate. |
| throws | InvalidArgumentException | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildCondition(array|string|ExpressionInterface|null $condition, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildExpression()
Builds given $expression.
See also:
| public abstract string buildExpression ( Yiisoft\Db\Expression\ExpressionInterface $expression, array &$params = [] ) | ||
| $expression | Yiisoft\Db\Expression\ExpressionInterface |
The expression to build. |
| $params | array |
The parameters to bind to the generated SQL statement. These parameters will be included in the result with the more parameters generated during the expression building process. |
| return | string |
The SQL statement that won't be neither quoted nor encoded before passing to DBMS. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
When $expression building isn't supported by the {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface} implementation. |
public function buildExpression(ExpressionInterface $expression, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildFor()
Builds a SQL for FOR clause.
| public abstract string buildFor ( array $values ) | ||
| $values | array |
The value to build. |
| return | string |
The result SQL. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
When the |
public function buildFor(array $values): string;
| public abstract string buildFrom ( array $tables, array &$params ) | ||
| $tables | array |
The tables to process. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildFrom(array $tables, array &$params): string;
| public abstract string buildGroupBy ( array $columns, array &$params = [] ) | ||
| $columns | array |
The columns to group by. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::groupBy()} on how to specify this parameter. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildGroupBy(array $columns, array &$params = []): string;
| public abstract string buildHaving ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] ) | ||
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string|null |
The condition specification. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildHaving(array|ExpressionInterface|string|null $condition, array &$params = []): string;
| public abstract string buildJoin ( array $joins, array &$params ) | ||
| $joins | array |
The joins to process. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException |
If the |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildJoin(array $joins, array &$params): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildLimit()
See also:
- Yiisoft\Db\Query\Query::limit() For more details.
- Yiisoft\Db\Query\Query::offset() For more details.
| public abstract string buildLimit ( Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit, Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset ) | ||
| $limit | Yiisoft\Db\Expression\ExpressionInterface|integer|null |
The limit number. |
| $offset | Yiisoft\Db\Expression\ExpressionInterface|integer|null |
The offset number. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildLimit(ExpressionInterface|int|null $limit, ExpressionInterface|int|null $offset): string;
| public abstract string buildOrderBy ( array $columns, array &$params = [] ) | ||
| $columns | array |
The columns to order by. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::orderBy()} on how to specify this parameter. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildOrderBy(array $columns, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildOrderByAndLimit()
Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
| public abstract string buildOrderByAndLimit ( string $sql, array $orderBy, Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit, Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset, array &$params = [] ) | ||
| $sql | string |
The existing SQL (without |
| $orderBy | array |
The order by columns. {@see \Yiisoft\Db\Query\Query::orderBy()} for more details on how to specify this parameter. |
| $limit | Yiisoft\Db\Expression\ExpressionInterface|integer|null |
The limit number. {@see \Yiisoft\Db\Query\Query::limit()} For more details. |
| $offset | Yiisoft\Db\Expression\ExpressionInterface|integer|null |
The offset number. {@see \Yiisoft\Db\Query\Query::offset()} For more details. |
| $params | array |
The binding parameters to populate. |
| return | string |
The SQL completed with |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildOrderByAndLimit(
string $sql,
array $orderBy,
ExpressionInterface|int|null $limit,
ExpressionInterface|int|null $offset,
array &$params = [],
): string;
| public abstract string buildSelect ( array $columns, array &$params, boolean $distinct = false, string|null $selectOption = null ) | ||
| $columns | array |
The columns to select. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::select()} on how to specify this parameter. |
| $params | array |
The binding parameters to populate. |
| $distinct | boolean |
Whether to add |
| $selectOption | string|null |
The |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException | |
public function buildSelect(
array $columns,
array &$params,
bool $distinct = false,
?string $selectOption = null,
): string;
| public abstract string buildUnion ( array $unions, array &$params ) | ||
| $unions | array |
The |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildUnion(array $unions, array &$params): string;
Securely converts PHP values to their SQL representations with using bind parameters where necessary:
- array values are converted to JSON or SQL array expressions;
- bool values are converted to TRUE or FALSE or other DBMS-specific boolean representations;
- float and int values are converted to their string representations;
- null values are converted to NULL;
- object values are converted to their SQL representation based on their type;
- resource values are bound as LOB parameters;
- closed resource throw an {@see InvalidArgumentException};
- string values are bound as string parameters;
- other values are bound as parameters.
| public abstract string buildValue ( mixed $value, array &$params ) | ||
| $value | mixed |
The PHP value to be converted to SQL. |
| $params | array |
The parameters array to which the bound parameters will be added. |
| return | string |
The SQL representation of the value. |
|---|---|---|
| throws | InvalidArgumentException | |
public function buildValue(mixed $value, array &$params): string;
| public abstract string buildWhere ( array|Yiisoft\Db\QueryBuilder\Condition\ConditionInterface|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] ) | ||
| $condition | array|Yiisoft\Db\QueryBuilder\Condition\ConditionInterface|Yiisoft\Db\Expression\ExpressionInterface|string|null |
The condition built from {@see \Yiisoft\Db\Query\Query::where()}. |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildWhere(
array|string|ConditionInterface|ExpressionInterface|null $condition,
array &$params = [],
): string;
| public abstract string buildWithQueries ( Yiisoft\Db\Query\WithQuery[] $withQueries, array &$params ) | ||
| $withQueries | Yiisoft\Db\Query\WithQuery[] |
The |
| $params | array |
The binding parameters to populate. |
| return | string |
The |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function buildWithQueries(array $withQueries, array &$params): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::checkIntegrity()
Builds an SQL statement for enabling or disabling integrity check.
| public abstract string checkIntegrity ( string $schema = '', string $table = '', boolean $check = true ) | ||
| $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. |
| $check | boolean |
Whether to turn on or off the integrity check. |
| return | string |
The SQL statement for checking integrity. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::createConditionFromArray()
Transforms one condition defined in array format (as described in {@see Query::where()} to instance of {@see ConditionInterface}).
See also Yiisoft\Db\QueryBuilder\Condition\ConditionInterface According to conditions class map.
| public abstract Yiisoft\Db\QueryBuilder\Condition\ConditionInterface createConditionFromArray ( array $condition ) | ||
| $condition | array |
The condition in array format. |
| throws | InvalidArgumentException | |
|---|---|---|
public function createConditionFromArray(array $condition): ConditionInterface;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::createIndex()
Builds an SQL statement for creating a new index.
| public abstract string createIndex ( string $table, string $name, array|string $columns, string|null $indexType = null, string|null $indexMethod = null ) | ||
| $table | string |
The table to create the new index for. |
| $name | string |
The name of the index. |
| $columns | array|string |
The column(s) to include in the index. If there are many columns, separate them with commas or use an array to represent them. |
| $indexType | string|null |
The index type, |
| $indexMethod | string|null |
The index organization method, if supported by DBMS.
See driver specific |
| return | string |
The SQL statement for creating a new index. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function createIndex(
string $table,
string $name,
array|string $columns,
?string $indexType = null,
?string $indexMethod = null,
): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::createTable()
Builds an SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name is the name of the column which will be properly quoted by the method, and definition is the type of the column which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.
The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert string not null to varchar(255) not null
and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).
The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.
$this->createTable(
'example_table',
[
'id' => ColumnBuilder::primaryKey(),
'name' => ColumnBuilder::string(64)->notNull(),
'type' => ColumnBuilder::integer()->notNull()->defaultValue(10),
'description' => ColumnBuilder::text(),
'rule_name' => ColumnBuilder::string(64),
'data' => ColumnBuilder::text(),
'created_at' => ColumnBuilder::datetime()->notNull(),
'updated_at' => ColumnBuilder::datetime(),
],
);
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly put into the generated SQL.
| public abstract string createTable ( string $table, (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[] $columns, string|null $options = null ) | ||
| $table | string |
The name of the table to create. |
| $columns | (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[] |
The columns (name => definition) in the new table.
The definition can be |
| $options | string|null |
More SQL fragments to append to the generated SQL. |
| return | string |
The SQL statement for creating a new DB table. Note: The method will quote the |
|---|---|---|
public function createTable(string $table, array $columns, ?string $options = null): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::createView()
Creates an SQL View.
| public abstract string createView ( string $viewName, Yiisoft\Db\Query\QueryInterface|string $subQuery ) | ||
| $viewName | string |
The name of the view to create. |
| $subQuery | Yiisoft\Db\Query\QueryInterface|string |
The select statement which defines the view. This can be either a string or a {@see \Yiisoft\Db\QueryBuilder\Query} object. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
| throws | Yiisoft\Db\Exception\Exception | |
public function createView(string $viewName, QueryInterface|string $subQuery): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::delete()
Creates a DELETE SQL statement.
For example,
$sql = $queryBuilder->delete('user', 'status = 0');
| public abstract string delete ( string $table, array|string $condition, array &$params ) | ||
| $table | string |
The table to delete the data from. |
| $condition | array|string |
The condition to put in the |
| $params | array |
The binding parameters to change by this method to bind to DB command later. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function delete(string $table, array|string $condition, array &$params): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCheck()
Creates an SQL command for dropping a check constraint.
| public abstract string dropCheck ( string $table, string $name ) | ||
| $table | string |
The table whose check constraint is to drop. |
| $name | string |
The name of the check constraint to drop. |
| return | string |
The SQL statement for dropping a check constraint. Note: The method will quote the |
|---|---|---|
public function dropCheck(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropColumn()
Builds an SQL statement for dropping a DB column.
| public abstract string dropColumn ( string $table, string $column ) | ||
| $table | string |
The table whose column is to drop. |
| $column | string |
The name of the column to drop. |
| return | string |
The SQL statement for dropping a DB column. Note: The method will quote the |
|---|---|---|
public function dropColumn(string $table, string $column): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCommentFromColumn()
Builds an SQL command for dropping comment to column.
| public abstract string dropCommentFromColumn ( string $table, string $column ) | ||
| $table | string |
The table whose column is to comment. |
| $column | string |
The name of the column to comment. |
| return | string |
The SQL statement for dropping comment on column. Note: The method will quote the |
|---|---|---|
public function dropCommentFromColumn(string $table, string $column): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCommentFromTable()
Builds an SQL command for dropping comment to the table.
| public abstract string dropCommentFromTable ( string $table ) | ||
| $table | string |
The table whose column is to comment. |
| return | string |
The SQL statement for dropping comment on column. Note: The method will quote the |
|---|---|---|
public function dropCommentFromTable(string $table): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropDefaultValue()
Creates an SQL command for dropping a default value constraint.
| public abstract string dropDefaultValue ( string $table, string $name ) | ||
| $table | string |
The table whose default value constraint is to drop. |
| $name | string |
The name of the default value constraint to drop. |
| return | string |
The SQL statement for dropping a default value constraint. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function dropDefaultValue(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropForeignKey()
Builds an SQL statement for dropping a foreign key constraint.
| public abstract string dropForeignKey ( string $table, string $name ) | ||
| $table | string |
The table whose foreign is to drop. |
| $name | string |
The name of the foreign key constraint to drop. |
| return | string |
The SQL statement for dropping a foreign key constraint. Note: The method will quote the |
|---|---|---|
public function dropForeignKey(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropIndex()
Builds an SQL statement for dropping an index.
| public abstract string dropIndex ( string $table, string $name ) | ||
| $table | string |
The table whose index is to drop. |
| $name | string |
The name of the index to drop. |
| return | string |
The SQL statement for dropping an index. Note: The method will quote the |
|---|---|---|
public function dropIndex(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropPrimaryKey()
Builds an SQL statement for removing a primary key constraint to an existing table.
| public abstract string dropPrimaryKey ( string $table, string $name ) | ||
| $table | string |
The table to remove the primary key constraint from. |
| $name | string |
The name of the primary key constraint to remove. |
| return | string |
The SQL statement for removing a primary key constraint from an existing table. Note: The method will quote the |
|---|---|---|
public function dropPrimaryKey(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropTable()
Builds an SQL statement for dropping a DB table.
| public abstract string dropTable ( string $table, boolean $ifExists = false, boolean $cascade = false ) | ||
| $table | string |
The table to drop. |
| $ifExists | boolean |
Do not throw an error if the table does not exist. |
| $cascade | boolean |
Automatically drop objects that depend on the table. |
| return | string |
The SQL statement for dropping a DB table. Note: The method will quote the |
|---|---|---|
public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropUnique()
Creates an SQL command for dropping a unique constraint.
| public abstract string dropUnique ( string $table, string $name ) | ||
| $table | string |
The table whose unique constraint is to drop. |
| $name | string |
The name of the unique constraint to drop. |
| return | string |
The SQL statement for dropping an unique constraint. Note: The method will quote the |
|---|---|---|
public function dropUnique(string $table, string $name): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropView()
Drops an SQL View.
| public abstract string dropView ( string $viewName ) | ||
| $viewName | string |
The name of the view to drop. |
| return | string |
The Note: The method will quote the |
|---|---|---|
public function dropView(string $viewName): string;
Returns the column definition builder for the current DBMS.
| public abstract Yiisoft\Db\QueryBuilder\ColumnDefinitionBuilderInterface getColumnDefinitionBuilder ( ) |
public function getColumnDefinitionBuilder(): ColumnDefinitionBuilderInterface;
Returns the column factory for creating column instances.
| public abstract Yiisoft\Db\Schema\Column\ColumnFactoryInterface getColumnFactory ( ) |
public function getColumnFactory(): ColumnFactoryInterface;
Gets an object of {@see ExpressionBuilderInterface} that's suitable for $expression.
Uses {@see \Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder::expressionBuilders} an array to find a suitable builder class.
| public abstract Yiisoft\Db\Expression\ExpressionBuilderInterface getExpressionBuilder ( Yiisoft\Db\Expression\ExpressionInterface $expression ) | ||
| $expression | Yiisoft\Db\Expression\ExpressionInterface |
The expression to build. |
| throws | Yiisoft\Db\Exception\NotSupportedException |
When expression building isn't supported by this QueryBuilder. |
|---|---|---|
public function getExpressionBuilder(ExpressionInterface $expression): ExpressionBuilderInterface;
| public abstract Yiisoft\Db\Schema\QuoterInterface getQuoter ( ) | ||
| return | Yiisoft\Db\Schema\QuoterInterface |
The quoter instance. |
|---|---|---|
public function getQuoter(): QuoterInterface;
Returns {@see ServerInfoInterface} instance that provides information about the database server.
| public abstract Yiisoft\Db\Connection\ServerInfoInterface getServerInfo ( ) |
public function getServerInfo(): ServerInfoInterface;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insert()
Creates an INSERT SQL statement.
For example,
$sql = $queryBuilder->insert('user', [
'name' => 'Sam',
'age' => 30,
], $params);
| public abstract string insert ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns, array &$params = [] ) | ||
| $table | string |
The table to insert new rows into. |
| $columns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or instance of
{@see \Yiisoft\Db\QueryBuilder\Query} to perform |
| $params | array |
The binding parameters that will be generated by this method. They should be bound to the DB command later. |
| return | string |
The INSERT SQL. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function insert(string $table, array|QueryInterface $columns, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insertBatch()
Generates a batch INSERT SQL statement.
For example,
$sql = $queryBuilder->insertBatch('user', [
['Tom', 30],
['Jane', 20],
['Linda', 25],
], ['name', 'age']);
or as associative arrays where the keys are column names
$queryBuilder->insertBatch('user', [
['name' => 'Tom', 'age' => 30],
['name' => 'Jane', 'age' => 20],
['name' => 'Linda', 'age' => 25],
]);
| public abstract string insertBatch ( string $table, iterable $rows, string[] $columns = [], array &$params = [] ) | ||
| $table | string |
The table to insert new rows into. |
| $rows | iterable |
The rows to batch-insert into the table. |
| $columns | string[] |
The column names of the table. |
| $params | array |
The binding parameters. This parameter exists. |
| return | string |
The batch INSERT SQL statement. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function insertBatch(string $table, iterable $rows, array $columns = [], array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insertReturningPks()
Creates an INSERT SQL statement with returning inserted primary key values.
| public abstract string insertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns, array &$params = [] ) | ||
| $table | string |
The table to insert new rows into. |
| $columns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or instance of
{@see \Yiisoft\Db\QueryBuilder\Query} to perform |
| $params | array |
The binding parameters that will be generated by this method. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function insertReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::isTypecastingEnabled()
Returns whether type casting is enabled for the query builder.
See also withTypecasting().
| public abstract boolean isTypecastingEnabled ( ) |
public function isTypecastingEnabled(): bool;
Converts a {@see Param} object to its SQL representation and quotes it if necessary.
Used when the bind parameter cannot be used in the SQL query.
| public abstract string prepareParam ( Yiisoft\Db\Expression\Value\Param $param ) | ||
| $param | Yiisoft\Db\Expression\Value\Param | |
public function prepareParam(Param $param): string;
Converts a value to its SQL representation and quotes it if necessary.
Used when the bind parameter cannot be used in the SQL query.
| public abstract string prepareValue ( mixed $value ) | ||
| $value | mixed | |
public function prepareValue(mixed $value): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::renameColumn()
Builds an SQL statement for renaming a column.
| public abstract string renameColumn ( string $table, string $oldName, string $newName ) | ||
| $table | string |
The table whose column is to rename. |
| $oldName | string |
The old name of the column. |
| $newName | string |
The new name of the column. |
| return | string |
The SQL statement for renaming a DB column. Note: The method will quote the |
|---|---|---|
public function renameColumn(string $table, string $oldName, string $newName): string;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::renameTable()
Builds an SQL statement for renaming a DB table.
| public abstract string renameTable ( string $oldName, string $newName ) | ||
| $oldName | string |
The table to rename. |
| $newName | string |
The new table name. |
| return | string |
The SQL statement for renaming a DB table. Note: The method will quote the |
|---|---|---|
public function renameTable(string $oldName, string $newName): string;
Replaces placeholders in the SQL string with the corresponding values.
| public abstract string replacePlaceholders ( string $sql, string[] $replacements ) | ||
| $sql | string |
SQL expression where the placeholder should be replaced. |
| $replacements | string[] |
Replacements for placeholders with placeholder names as keys and values as follows:
|
| return | string |
SQL expression with replaced placeholders. |
|---|---|---|
public function replacePlaceholders(string $sql, array $replacements): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::resetSequence()
Creates an SQL statement for resetting the sequence value of a table's primary key.
The sequence will be reset such that the primary key of the next new row inserted will have the specified value or 1.
| public abstract string resetSequence ( string $table, integer|string|null $value = null ) | ||
| $table | string |
The name of the table whose primary key sequence will be reset. |
| $value | integer|string|null |
The value for the primary key of the next new row inserted. If this isn't set, the next new row's primary key will have value 1. |
| return | string |
The SQL statement for a resetting sequence. Note: The method will escape the table and column names. |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
| throws | Yiisoft\Db\Exception\Exception | |
public function resetSequence(string $table, int|string|null $value = null): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::selectExists()
Creates a SELECT EXISTS() SQL statement.
| public abstract string selectExists ( string $rawSql ) | ||
| $rawSql | string |
The sub-query in a raw form to select from. |
| return | string |
The |
|---|---|---|
public function selectExists(string $rawSql): string;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::setConditionClasses()
Setter for {@see AbstractDQLQueryBuilder::conditionClasses} property.
| public abstract void setConditionClasses ( string[] $classes ) | ||
| $classes | string[] |
Map of condition aliases to condition classes. For example:
|
public function setConditionClasses(array $classes): void;
Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::setExpressionBuilders()
Setter for {@see AbstractDQLQueryBuilder::expressionBuilders} property.
| public abstract void setExpressionBuilders ( string[] $builders ) | ||
| $builders | string[] |
Array of builders to merge with the pre-defined ones in property. |
public function setExpressionBuilders(array $builders): void;
| public abstract void setSeparator ( string $separator ) | ||
| $separator | string |
The separator between different fragments of an SQL statement. Defaults to an empty space. This is mainly used by {@see \Yiisoft\Db\QueryBuilder\build()} when generating a SQL statement. |
public function setSeparator(string $separator): void;
Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::truncateTable()
Builds an SQL statement for truncating a DB table.
| public abstract string truncateTable ( string $table ) | ||
| $table | string |
The table to truncate. |
| return | string |
The SQL statement for truncating a DB table. Note: The method will quote the |
|---|---|---|
public function truncateTable(string $table): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::update()
Creates an UPDATE SQL statement.
For example,
$params = [];
$sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
| public abstract string update ( string $table, array $columns, array|Yiisoft\Db\Expression\ExpressionInterface|string $condition, array|Yiisoft\Db\Expression\ExpressionInterface|string|null $from = null, array &$params = [] ) | ||
| $table | string |
The table to update. |
| $columns | array |
The column data (name => value) to update the table. |
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string |
The condition to put in the |
| $from | array|Yiisoft\Db\Expression\ExpressionInterface|string|null |
The FROM part. Please refer to {@see \Yiisoft\Db\QueryBuilder\QueryPartsInterface::from()} On how to specify FROM part. |
| $params | array |
The binding parameters that will be modified by this method so that they can be bound to DB command later. |
| return | string |
The UPDATE SQL. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function update(
string $table,
array $columns,
array|ExpressionInterface|string $condition,
array|ExpressionInterface|string|null $from = null,
array &$params = [],
): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::upsert()
Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do.
For example,
$sql = $queryBuilder->upsert('pages', [
'name' => 'Front page',
'url' => 'http://example.com/', // url is unique
'visits' => 0,
], [
'visits' => new Expression('visits + 1'),
], $params);
| public abstract string upsert ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, array &$params = [] ) | ||
| $table | string |
The table to insert rows into or update new rows in. |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or
instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform |
| $updateColumns | array|boolean |
The column data (name => value) to update if they already exist. If |
| $params | array |
The binding parameters that will be generated by this method. They should be bound to the DB command later. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function upsert(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
array &$params = [],
): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::upsertReturning()
Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do, with returning values from the specified columns.
The method will quote the table, insertColumns, updateColumns and returnColumns parameters before using
it in the generated SQL.
| public abstract string upsertReturning ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, string[]|null $returnColumns = null, array &$params = [] ) | ||
| $table | string |
The table to insert rows into or update new rows in. |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or
instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform |
| $updateColumns | array|boolean |
The column data (name => value) to update if they already exist. If |
| $returnColumns | string[]|null |
The column names to return values from. |
| $params | array |
The binding parameters that will be generated by this method. They should be bound to the DB command later. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function upsertReturning(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
?array $returnColumns = null,
array &$params = [],
): string;
Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::withTypecasting()
Clones the current instance and sets whether type casting is required for the query builder.
See also isTypecastingEnabled().
| public abstract Yiisoft\Db\QueryBuilder\QueryBuilderInterface withTypecasting ( boolean $typecasting = true ) | ||
| $typecasting | boolean |
Whether type casting is required. Defaults to |
public function withTypecasting(bool $typecasting = true): static;
Signup or Login in order to comment.