0 follower

Interface Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface

Implemented byYiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder, Yiisoft\Db\QueryBuilder\QueryBuilderInterface

Defines methods for building SQL statements for DML (data manipulation language).

Psalm Types

Name Value
BatchValues iterable<iterable<array-key, mixed>>

Public Methods

Hide inherited methods

Method Description Defined By
delete() Creates a DELETE SQL statement. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
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
resetSequence() Creates an SQL statement for resetting the sequence value of a table's primary key. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
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

Hide inherited methods

delete() public abstract method

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 WHERE part. Please refer to {@see \Yiisoft\Db\QueryBuilder\Query::where()} On how to specify condition.

$params array

The binding parameters to change by this method to bind to DB command later.

return string

The DELETE 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 delete(string $table, array|string $condition, array &$params): string;

            
insert() public abstract method

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 INSERT INTO ... SELECT SQL statement. Passing of {@see \Yiisoft\Db\QueryBuilder\Query}.

$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;

            
insertBatch() public abstract method

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;

            
insertReturningPks() public abstract method

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 INSERT INTO ... SELECT SQL statement.

$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;

            
isTypecastingEnabled() public abstract method

Returns whether type casting is enabled for the query builder.

See also withTypecasting().

public abstract boolean isTypecastingEnabled ( )

                public function isTypecastingEnabled(): bool;

            
resetSequence() public abstract method

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;

            
update() public abstract method

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 WHERE part. Please refer to {@see \Yiisoft\Db\QueryBuilder\QueryPartsInterface::where()} On how to specify condition.

$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;

            
upsert() public abstract method

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 INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

The column data (name => value) to update if they already exist. If true is passed, the column data will be updated to match the insert column data. If false is passed, no update will be performed if the column data already exist.

$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;

            
upsertReturning() public abstract method

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 INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

The column data (name => value) to update if they already exist. If true is passed, the column data will be updated to match the insert column data. If false is passed, no update will be performed if the column data already exist.

$returnColumns string[]|null

The column names to return values from. null means all columns.

$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;

            
withTypecasting() public abstract method

Clones the current instance and sets whether type casting is required for the query builder.

See also isTypecastingEnabled().

public abstract Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface withTypecasting ( boolean $typecasting true )
$typecasting boolean

Whether type casting is required. Defaults to true.

                public function withTypecasting(bool $typecasting = true): static;