Interface Yiisoft\Db\Driver\Pdo\PdoCommandInterface
| Extends | Yiisoft\Db\Command\CommandInterface |
|---|---|
| Implemented by | Yiisoft\Db\Driver\Pdo\AbstractPdoCommand |
This interface defines the method {@see getPdoStatement()} that must be implemented by {@see \PDO}.
See also Yiisoft\Db\Command\CommandInterface.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| addCheck() | Creates an SQL command for adding a CHECK constraint to an existing table. |
Yiisoft\Db\Command\CommandInterface |
| addColumn() | Creates an SQL command for adding a new DB column. | Yiisoft\Db\Command\CommandInterface |
| addCommentOnColumn() | Builds an SQL command for adding a comment to a column. | Yiisoft\Db\Command\CommandInterface |
| addCommentOnTable() | Builds an SQL command for adding comment to the table. | Yiisoft\Db\Command\CommandInterface |
| addDefaultValue() | Creates an SQL command for adding a default value constraint to an existing table. | Yiisoft\Db\Command\CommandInterface |
| addForeignKey() | Creates an SQL command for adding a foreign key constraint to an existing table. | Yiisoft\Db\Command\CommandInterface |
| addPrimaryKey() | Creates an SQL command for adding a primary key constraint to an existing table. | Yiisoft\Db\Command\CommandInterface |
| addUnique() | Creates an SQL command for adding a unique constraint to an existing table. | Yiisoft\Db\Command\CommandInterface |
| alterColumn() | Creates an SQL command for changing the definition of a column. | Yiisoft\Db\Command\CommandInterface |
| bindParam() | Binds a parameter to the SQL statement to be executed. | Yiisoft\Db\Command\CommandInterface |
| bindValue() | Binds a value to a parameter. | Yiisoft\Db\Command\CommandInterface |
| bindValues() | Binds a list of values to the corresponding parameters. | Yiisoft\Db\Command\CommandInterface |
| cancel() | Cancels the execution of the SQL statement. | Yiisoft\Db\Command\CommandInterface |
| checkIntegrity() | Builds an SQL command for enabling or disabling integrity check. | Yiisoft\Db\Command\CommandInterface |
| createIndex() | Creates an SQL command for creating a new index. | Yiisoft\Db\Command\CommandInterface |
| createTable() | Creates an SQL command for creating a new DB table. | Yiisoft\Db\Command\CommandInterface |
| createView() | Creates a SQL View. | Yiisoft\Db\Command\CommandInterface |
| delete() | Creates a DELETE command. | Yiisoft\Db\Command\CommandInterface |
| dropCheck() | Creates an SQL command for dropping a check constraint. | Yiisoft\Db\Command\CommandInterface |
| dropColumn() | Creates an SQL command for dropping a DB column. | Yiisoft\Db\Command\CommandInterface |
| dropCommentFromColumn() | Builds an SQL command for dropping comment from column. | Yiisoft\Db\Command\CommandInterface |
| dropCommentFromTable() | Builds an SQL command for dropping comment from the table. | Yiisoft\Db\Command\CommandInterface |
| dropDefaultValue() | Creates an SQL command for dropping a default value constraint. | Yiisoft\Db\Command\CommandInterface |
| dropForeignKey() | Creates an SQL command for dropping a foreign key constraint. | Yiisoft\Db\Command\CommandInterface |
| dropIndex() | Creates an SQL command for dropping an index. | Yiisoft\Db\Command\CommandInterface |
| dropPrimaryKey() | Creates an SQL command for removing a primary key constraint to an existing table. | Yiisoft\Db\Command\CommandInterface |
| dropTable() | Creates an SQL command for dropping a DB table. | Yiisoft\Db\Command\CommandInterface |
| dropUnique() | Creates an SQL command for dropping a unique constraint. | Yiisoft\Db\Command\CommandInterface |
| dropView() | Drops an SQL View. | Yiisoft\Db\Command\CommandInterface |
| execute() | Executes the SQL statement. | Yiisoft\Db\Command\CommandInterface |
| getParams() | Return the params used in the last query. | Yiisoft\Db\Command\CommandInterface |
| getPdoStatement() | Yiisoft\Db\Driver\Pdo\PdoCommandInterface | |
| getRawSql() | Returns the raw SQL by inserting parameter values into the corresponding placeholders in {@see getSql()}. | Yiisoft\Db\Command\CommandInterface |
| getSql() | Returns the SQL statement for this command. | Yiisoft\Db\Command\CommandInterface |
| insert() | Creates an INSERT command. | Yiisoft\Db\Command\CommandInterface |
| insertBatch() | Creates a batch INSERT command. | Yiisoft\Db\Command\CommandInterface |
| insertReturningPks() | Attention! Please use function only as a last resort. The feature will be refactored in future releases. | Yiisoft\Db\Command\CommandInterface |
| prepare() | Prepares the SQL statement to be executed. | Yiisoft\Db\Command\CommandInterface |
| query() | Executes the SQL statement and returns a query result. | Yiisoft\Db\Command\CommandInterface |
| queryAll() | Executes the SQL statement and returns ALL rows at once. | Yiisoft\Db\Command\CommandInterface |
| queryColumn() | Execute the SQL statement and returns the first column of the result. | Yiisoft\Db\Command\CommandInterface |
| queryOne() | Executes the SQL statement and returns the first row of the result. | Yiisoft\Db\Command\CommandInterface |
| queryScalar() | Execute the SQL statement and returns the value of the first column in the first row of data. | Yiisoft\Db\Command\CommandInterface |
| renameColumn() | Creates an SQL command for renaming a column. | Yiisoft\Db\Command\CommandInterface |
| renameTable() | Creates an SQL command for renaming a DB table. | Yiisoft\Db\Command\CommandInterface |
| resetSequence() | Executes a db command resetting the sequence value of a table's primary key. | Yiisoft\Db\Command\CommandInterface |
| setRawSql() | Specifies the SQL statement to execute. | Yiisoft\Db\Command\CommandInterface |
| setRetryHandler() | Sets a closure (anonymous function) which called when a database exception is thrown when executing the command. | Yiisoft\Db\Command\CommandInterface |
| setSql() | Specifies the SQL statement to execute. The SQL statement will be quoted using {@see ConnectionInterface::quoteSql()}. | Yiisoft\Db\Command\CommandInterface |
| showDatabases() | List all database names in the current connection. | Yiisoft\Db\Command\CommandInterface |
| truncateTable() | Creates an SQL command for truncating a DB table. | Yiisoft\Db\Command\CommandInterface |
| update() | Creates an UPDATE command. | Yiisoft\Db\Command\CommandInterface |
| upsert() | Creates a command to insert rows into a database table if they don't already exist (matching unique constraints) or update them if they do. | Yiisoft\Db\Command\CommandInterface |
| upsertReturning() | Creates a command to insert rows into a database table if they don't already exist (matching unique constraints) or update them if they do, returning values from the specified columns. | Yiisoft\Db\Command\CommandInterface |
| upsertReturningPks() | Creates a command to insert rows into a database table if they don't already exist (matching unique constraints) or update them if they do, with returning inserted or updated primary key values. | Yiisoft\Db\Command\CommandInterface |
| withDbTypecasting() | Returns copy of the instance with enabled or disabled typecasting of values when inserting or updating records. | Yiisoft\Db\Command\CommandInterface |
| withPhpTypecasting() | Returns a copy of the instance with enabled or disabled typecasting of values when retrieving records from DB. | Yiisoft\Db\Command\CommandInterface |
| withTypecasting() | Returns a copy of the instance with enabled or disabled typecasting of values when inserting, updating or retrieving records from DB. | Yiisoft\Db\Command\CommandInterface |
Method Details
Defined in: Yiisoft\Db\Command\CommandInterface::addCheck()
Creates an SQL command for adding a CHECK constraint to an existing table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addCheck ( string $table, string $name, string $expression ) | ||
| $table | string |
The name of the table to add check constraint to. |
| $name | string |
The name of the check constraint. |
| $expression | string |
The SQL of the Note: The method will quote the |
public function addCheck(string $table, string $name, string $expression): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addColumn()
Creates an SQL command for adding a new DB column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string |
The name of the table to add new column to. |
| $column | string |
The name of the new column. |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column type.
{@see \Yiisoft\Db\Command\QueryBuilder::buildColumnDefinition()} will be called to convert the given column type to the database one.
For example, Note: The method will quote the |
public function addColumn(string $table, string $column, ColumnInterface|string $type): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addCommentOnColumn()
Builds an SQL command for adding a comment to a column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addCommentOnColumn ( string $table, string $column, string $comment ) | ||
| $table | string |
The name of the table whose column is to comment. |
| $column | string |
The name of the column to comment. |
| $comment | string |
The text of the comment. |
| throws | Exception |
Note: The method will quote the |
|---|---|---|
public function addCommentOnColumn(string $table, string $column, string $comment): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addCommentOnTable()
Builds an SQL command for adding comment to the table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addCommentOnTable ( string $table, string $comment ) | ||
| $table | string |
The name of the table whose column is to comment. |
| $comment | string |
The text of the comment to add. |
| throws | Exception |
Note: The method will quote the |
|---|---|---|
public function addCommentOnTable(string $table, string $comment): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addDefaultValue()
Creates an SQL command for adding a default value constraint to an existing table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addDefaultValue ( string $table, string $name, string $column, mixed $value ) | ||
| $table | string |
The name of the table to add constraint to. |
| $name | string |
The name of the default value constraint. |
| $column | string |
The name of the column to add constraint to. |
| $value | mixed |
Default value. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
Note: The method will quote the |
public function addDefaultValue(string $table, string $name, string $column, mixed $value): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addForeignKey()
Creates an SQL command 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 Yiisoft\Db\Driver\Pdo\PdoCommandInterface addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete = null, string|null $update = null ) | ||
| $table | string |
The name of the table to add foreign key constraint to. |
| $name | string |
The name of the foreign key constraint. |
| $columns | array|string |
The name of the column to add foreign key constraint to. If there are many columns, separate them with commas. |
| $referenceTable | string |
The name of 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. |
| $delete | string|null |
The |
| $update | string|null |
The |
| 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,
): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addPrimaryKey()
Creates an SQL command for adding a primary key constraint to an existing table.
The method will quote the table and column names.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addPrimaryKey ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The name of the table to add primary key constraint to. |
| $name | string |
The name of the primary key constraint. |
| $columns | string|string[] |
The comma separated string or array of columns that the primary key consists of. Note: The method will quote the |
public function addPrimaryKey(string $table, string $name, array|string $columns): static;
Defined in: Yiisoft\Db\Command\CommandInterface::addUnique()
Creates an SQL command for adding a unique constraint to an existing table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface addUnique ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The name of the table to add unique constraint to. |
| $name | string |
The name of the unique constraint. |
| $columns | string|string[] |
The name of the column to add unique constraint to. If there are many columns, use an array or separate them with commas. Note: The method will quote the |
public function addUnique(string $table, string $name, array|string $columns): static;
Defined in: Yiisoft\Db\Command\CommandInterface::alterColumn()
Creates an SQL command for changing the definition of a column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface 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.
{@see \Yiisoft\Db\Command\QueryBuilder::buildColumnDefinition()} will be called to convert the give column type to the physical one.
For example, Note: The method will quote the |
public function alterColumn(string $table, string $column, ColumnInterface|string $type): static;
Defined in: Yiisoft\Db\Command\CommandInterface::bindParam()
Binds a parameter to the SQL statement to be executed.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface bindParam ( integer|string $name, mixed &$value, integer|null $dataType = null, integer|null $length = null, mixed|null $driverOptions = null ) | ||
| $name | integer|string |
The parameter identifier. For a prepared statement using named placeholders, this will be
a parameter name of the form |
| $value | mixed |
The PHP variable to bind to the SQL statement parameter (passed by reference). |
| $dataType | integer|null |
The {@see \Yiisoft\Db\Constant\DataType SQL data type} of the parameter. If |
| $length | integer|null |
The length of the data type. |
| $driverOptions | mixed|null |
The driver-specific options. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
public function bindParam(
int|string $name,
mixed &$value,
?int $dataType = null,
?int $length = null,
mixed $driverOptions = null,
): static;
Defined in: Yiisoft\Db\Command\CommandInterface::bindValue()
Binds a value to a parameter.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface bindValue ( integer|string $name, mixed $value, integer|null $dataType = null ) | ||
| $name | integer|string |
Parameter identifier. For a prepared statement using named placeholders, this will be a
parameter name of the form |
| $value | mixed |
The value to bind to the parameter. |
| $dataType | integer|null |
The {@see \Yiisoft\Db\Constant\DataType SQL data type} of the parameter. If null, the type is determined by the PHP type of the value. |
public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static;
Defined in: Yiisoft\Db\Command\CommandInterface::bindValues()
Binds a list of values to the corresponding parameters.
This is similar to {@see \Yiisoft\Db\Command\bindValue()} except that it binds many values at a time.
Note that the SQL data type of each value is determined by its PHP type.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface bindValues ( array|Yiisoft\Db\Expression\Value\Param[] $values ) | ||
| $values | array|Yiisoft\Db\Expression\Value\Param[] |
The values to bind. This must be given in terms of an associative
array with array keys being the parameter names, and an array values the corresponding parameter values,
for example, |
public function bindValues(array $values): static;
Defined in: Yiisoft\Db\Command\CommandInterface::cancel()
Cancels the execution of the SQL statement.
| public abstract void cancel ( ) |
public function cancel(): void;
Defined in: Yiisoft\Db\Command\CommandInterface::checkIntegrity()
Builds an SQL command for enabling or disabling integrity check.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface checkIntegrity ( string $schema, string $table, boolean $check = true ) | ||
| $schema | string |
The schema name of the tables. Defaults to empty string, meaning the current or default schema. |
| $table | string |
The table name to check. |
| $check | boolean |
Whether to turn the integrity check on or off. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
Note: The method will quote the |
public function checkIntegrity(string $schema, string $table, bool $check = true): static;
Defined in: Yiisoft\Db\Command\CommandInterface::createIndex()
Creates an SQL command for creating a new index.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface createIndex ( string $table, string $name, array|string $columns, string|null $indexType = null, string|null $indexMethod = null ) | ||
| $table | string |
The name of the table to create the 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. |
| $indexType | string|null |
The type of the index supported by DBMS {@see \Yiisoft\Db\Constant\IndexType} - for example: |
| $indexMethod | string|null |
The index organization method (with |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
public function createIndex(
string $table,
string $name,
array|string $columns,
?string $indexType = null,
?string $indexMethod = null,
): static;
Defined in: Yiisoft\Db\Command\CommandInterface::createTable()
Creates an SQL command 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\Constant\ColumnType abstract} or {@see \Yiisoft\Db\Constant\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.
The {@see \Yiisoft\Db\Command\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\Command\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.
The method will quote the table and columns parameter before using it in the generated SQL.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface 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. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function createTable(string $table, array $columns, ?string $options = null): static;
Defined in: Yiisoft\Db\Command\CommandInterface::createView()
Creates a SQL View.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface 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\Query\QueryInterface}. |
| throws | InvalidArgumentException | |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception |
Note: The method will quote the |
public function createView(string $viewName, QueryInterface|string $subQuery): static;
Defined in: Yiisoft\Db\Command\CommandInterface::delete()
Creates a DELETE command.
For example,
$connectionInterface->createCommand()->delete('user', 'status = 0')->execute();
or with using parameter binding for the condition:
$status = 0;
$connectionInterface->createCommand()->delete('user', 'status = :status', [':status' => $status])->execute();
The method will escape the table and column names.
Note that the created command isn't executed until you call {@see \Yiisoft\Db\Command\execute()}.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface delete ( string $table, array|string $condition = '', array $params = [] ) | ||
| $table | string |
The table to delete data from. |
| $condition | array|string |
The condition to put in the |
| $params | array |
The parameters to bind to the command. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
public function delete(string $table, array|string $condition = '', array $params = []): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropCheck()
Creates an SQL command for dropping a check constraint.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropCheck ( string $table, string $name ) | ||
| $table | string |
The name of the table whose check constraint to drop. |
| $name | string |
The name of the check constraint to drop. Note: The method will quote the |
public function dropCheck(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropColumn()
Creates an SQL command for dropping a DB column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropColumn ( string $table, string $column ) | ||
| $table | string |
The name of the table whose column is to drop. |
| $column | string |
The name of the column to drop. Note: The method will quote the |
public function dropColumn(string $table, string $column): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropCommentFromColumn()
Builds an SQL command for dropping comment from column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropCommentFromColumn ( string $table, string $column ) | ||
| $table | string |
The name of the table whose column to comment. |
| $column | string |
The name of the column to comment. Note: The method will quote the |
public function dropCommentFromColumn(string $table, string $column): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropCommentFromTable()
Builds an SQL command for dropping comment from the table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropCommentFromTable ( string $table ) | ||
| $table | string |
The name of the table whose column to comment. Note: The method will quote the |
public function dropCommentFromTable(string $table): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropDefaultValue()
Creates an SQL command for dropping a default value constraint.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropDefaultValue ( string $table, string $name ) | ||
| $table | string |
The name of the table whose default value constraint to drop. |
| $name | string |
The name of the default value constraint to drop. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
Note: The method will quote the |
public function dropDefaultValue(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropForeignKey()
Creates an SQL command for dropping a foreign key constraint.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropForeignKey ( string $table, string $name ) | ||
| $table | string |
The name of the table whose foreign is to drop. |
| $name | string |
The name of the foreign key constraint to drop. Note: The method will quote the |
public function dropForeignKey(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropIndex()
Creates an SQL command for dropping an index.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropIndex ( string $table, string $name ) | ||
| $table | string |
The name of the table whose index to drop. |
| $name | string |
The name of the index to drop. Note: The method will quote the |
public function dropIndex(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropPrimaryKey()
Creates an SQL command for removing a primary key constraint to an existing table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropPrimaryKey ( string $table, string $name ) | ||
| $table | string |
The name of the table to remove the primary key constraint from. |
| $name | string |
The name of the primary key constraint to remove. Note: The method will quote the |
public function dropPrimaryKey(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropTable()
Creates an SQL command for dropping a DB table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropTable ( string $table, boolean $ifExists = false, boolean $cascade = false ) | ||
| $table | string |
The name of 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. Note: The method will quote the |
public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropUnique()
Creates an SQL command for dropping a unique constraint.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropUnique ( string $table, string $name ) | ||
| $table | string |
The name of the table whose unique constraint to drop. |
| $name | string |
The name of the unique constraint to drop. Note: The method will quote the |
public function dropUnique(string $table, string $name): static;
Defined in: Yiisoft\Db\Command\CommandInterface::dropView()
Drops an SQL View.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface dropView ( string $viewName ) | ||
| $viewName | string |
The name of the view to drop. Note: The method will quote the |
public function dropView(string $viewName): static;
Defined in: Yiisoft\Db\Command\CommandInterface::execute()
Executes the SQL statement.
You should use this method only for executing a non-query SQL statement, such as INSERT, DELETE, UPDATE
SQLs. It returns no result set.
| public abstract integer execute ( ) | ||
| return | integer |
The number of rows execution affected. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function execute(): int;
Defined in: Yiisoft\Db\Command\CommandInterface::getParams()
Return the params used in the last query.
| public abstract array getParams ( boolean $asValues = true ) | ||
| $asValues | boolean |
By default, returns an array of name => value pairs. If set to |
| return | array |
The params used in the last query. |
|---|---|---|
public function getParams(bool $asValues = true): array;
| public abstract PDOStatement|null getPdoStatement ( ) | ||
| return | PDOStatement|null |
The PDO statement. |
|---|---|---|
public function getPdoStatement(): ?PDOStatement;
Defined in: Yiisoft\Db\Command\CommandInterface::getRawSql()
Returns the raw SQL by inserting parameter values into the corresponding placeholders in {@see getSql()}.
Note that you should mainly use the return value of this method for logging.
It's likely that this method returns an invalid SQL due to improper replacement of parameter placeholders.
| public abstract string getRawSql ( ) | ||
| return | string |
The raw SQL with parameter values inserted into the corresponding placeholders in {@see \Yiisoft\Db\Command\getSql()}. |
|---|---|---|
| throws | Exception | |
public function getRawSql(): string;
Defined in: Yiisoft\Db\Command\CommandInterface::getSql()
Returns the SQL statement for this command.
| public abstract string getSql ( ) | ||
| return | string |
The SQL statement to execute. |
|---|---|---|
public function getSql(): string;
Defined in: Yiisoft\Db\Command\CommandInterface::insert()
Creates an INSERT command.
For example,
$connectionInterface->createCommand()->insert(
'user',
[
'name' => 'Sam',
'age' => 30,
]
)->execute();
The method will escape the column names, and bind the values to be inserted.
Note that the created command isn't executed until you call {@see \Yiisoft\Db\Command\execute()}.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface insert ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns ) | ||
| $table | string |
The name of the table to insert new rows into. |
| $columns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or an instance of
{@see \Yiisoft\Db\Query\QueryInterface} to perform |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
Note: The method will quote the |
public function insert(string $table, array|QueryInterface $columns): static;
Defined in: Yiisoft\Db\Command\CommandInterface::insertBatch()
Creates a batch INSERT command.
For example,
$connectionInterface->createCommand()->insertBatch(
'user',
[
['Tom', 30],
['Jane', 20],
['Linda', 25],
],
['name', 'age']
)->execute();
or as associative arrays where the keys are column names
$connectionInterface->createCommand()->insertBatch(
'user',
[
['name' => 'Tom', 'age' => 30],
['name' => 'Jane', 'age' => 20],
['name' => 'Linda', 'age' => 25],
]
)->execute();
The method will escape the column names, and quote the values to insert.
Note that the values in each row must match the corresponding column names.
Also note that the created command isn't executed until {@see \Yiisoft\Db\Command\execute()} is called.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface insertBatch ( string $table, iterable $rows, string[] $columns = [] ) | ||
| $table | string |
The name of the table to insert new rows into. |
| $rows | iterable |
The rows to be batch inserted into the table. |
| $columns | string[] |
The column names. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
public function insertBatch(string $table, iterable $rows, array $columns = []): static;
Defined in: Yiisoft\Db\Command\CommandInterface::insertReturningPks()
Attention! Please use function only as a last resort. The feature will be refactored in future releases.
Executes the INSERT command, returning primary key inserted values.
| public abstract array insertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns ) | ||
| $table | string |
The name of the table to insert new rows into. |
| $columns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or an instance of
{@see \Yiisoft\Db\Query\QueryInterface} to perform |
| return | array |
The primary key values. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\InvalidCallException | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function insertReturningPks(string $table, array|QueryInterface $columns): array;
Defined in: Yiisoft\Db\Command\CommandInterface::prepare()
Prepares the SQL statement to be executed.
For complex SQL statement that's to be executed many times, this may improve performance.
For SQL statement with binding parameters, this method is invoked automatically.
| public abstract void prepare ( boolean|null $forRead = null ) | ||
| $forRead | boolean|null |
Whether the method call is for a read query. If null, it means the SQL statement should be used to decide whether it's to read or write. |
| throws | Yiisoft\Db\Exception\Exception |
If there is any DB error. |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
public function prepare(?bool $forRead = null): void;
Defined in: Yiisoft\Db\Command\CommandInterface::query()
Executes the SQL statement and returns a query result.
This method is for executing an SQL query that returns result set, such as SELECT.
| public abstract Yiisoft\Db\Query\DataReaderInterface query ( ) | ||
| return | Yiisoft\Db\Query\DataReaderInterface |
The reader object for fetching the query result. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function query(): DataReaderInterface;
Defined in: Yiisoft\Db\Command\CommandInterface::queryAll()
Executes the SQL statement and returns ALL rows at once.
| public abstract array[] queryAll ( ) | ||
| return | array[] |
All rows of the query result. Each array element is an |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function queryAll(): array;
Defined in: Yiisoft\Db\Command\CommandInterface::queryColumn()
Execute the SQL statement and returns the first column of the result.
This method is best used when you need only the first column of a result (that's the first element in each row).
| public abstract array queryColumn ( ) | ||
| return | array |
The first column of the query result. Empty array if the query results in nothing. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function queryColumn(): array;
Defined in: Yiisoft\Db\Command\CommandInterface::queryOne()
Executes the SQL statement and returns the first row of the result.
This method is best used when you need only the first row of a result.
| public abstract array|null queryOne ( ) | ||
| return | array|null |
The first row as an |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function queryOne(): ?array;
Defined in: Yiisoft\Db\Command\CommandInterface::queryScalar()
Execute the SQL statement and returns the value of the first column in the first row of data.
This method is best used when you need only a single value.
Do not use this method for boolean values as it returns false if there is no value.
| public abstract false|float|integer|string|null queryScalar ( ) | ||
| return | false|float|integer|string|null |
The value of the first column in the first row of the query result. False if there is no value. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Throwable |
If execution failed. |
public function queryScalar(): bool|string|int|float|null;
Defined in: Yiisoft\Db\Command\CommandInterface::renameColumn()
Creates an SQL command for renaming a column.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface renameColumn ( string $table, string $oldName, string $newName ) | ||
| $table | string |
The name of the table whose column is to rename. |
| $oldName | string |
The old name of the column. |
| $newName | string |
The new name of the column. Note: The method will quote the |
public function renameColumn(string $table, string $oldName, string $newName): static;
Defined in: Yiisoft\Db\Command\CommandInterface::renameTable()
Creates an SQL command for renaming a DB table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface renameTable ( string $table, string $newName ) | ||
| $table | string |
The name of the table to rename. |
| $newName | string |
The new table name. Note: The method will quote the |
public function renameTable(string $table, string $newName): static;
Defined in: Yiisoft\Db\Command\CommandInterface::resetSequence()
Executes a db command resetting the sequence value of a table's primary key.
Reason for execute is that some databases (Oracle) need several queries to do so.
The sequence is reset such that the primary key of the next new row inserted will have the specified value or the maximum existing value +1.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface resetSequence ( string $table, integer|string|null $value = null ) | ||
| $table | string |
The name of the table whose primary key sequence is 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 the maximum existing value +1. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\NotSupportedException |
Note: The method will quote the |
public function resetSequence(string $table, int|string|null $value = null): static;
Defined in: Yiisoft\Db\Command\CommandInterface::setRawSql()
Specifies the SQL statement to execute.
The SQL statement won't be modified in any way.
The earlier SQL (if any) will be discarded, and {@see \Yiisoft\Db\Expression\Value\Param} will be cleared as well.
See {@see \Yiisoft\Db\Command\reset()} for details.
See also:
- \Yiisoft\Db\Command\reset()
- cancel()
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface setRawSql ( string $sql ) | ||
| $sql | string |
The SQL statement to set. |
public function setRawSql(string $sql): static;
Defined in: Yiisoft\Db\Command\CommandInterface::setRetryHandler()
Sets a closure (anonymous function) which called when a database exception is thrown when executing the command.
The signature of the closure should be:
use Yiisoft\Db\Exception\Exception;
function (Exception $e, int $attempt): bool
{
// return true or false (whether to retry the command or throw $e)
}
The closure will receive an {@see \Yiisoft\Db\Exception\Exception} converted from the thrown database exception and the current attempt
to execute the command, starting from 1.
If the closure returns true, the command will be retried. If the closure returns false, the {@see \Yiisoft\Db\Exception\Exception}
will be thrown.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface setRetryHandler ( Closure|null $handler ) | ||
| $handler | Closure|null |
A PHP callback to handle database exceptions. |
public function setRetryHandler(?Closure $handler): static;
Defined in: Yiisoft\Db\Command\CommandInterface::setSql()
Specifies the SQL statement to execute. The SQL statement will be quoted using {@see ConnectionInterface::quoteSql()}.
The previous SQL (if any) will be discarded, and {@see \Yiisoft\Db\Expression\Value\Param} will be cleared as well. See {@see \Yiisoft\Db\Command\reset()} for details.
See also:
- \Yiisoft\Db\Command\reset()
- cancel()
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface setSql ( string $sql ) | ||
| $sql | string |
The SQL statement to set. |
public function setSql(string $sql): static;
Defined in: Yiisoft\Db\Command\CommandInterface::showDatabases()
List all database names in the current connection.
| public abstract array showDatabases ( ) |
public function showDatabases(): array;
Defined in: Yiisoft\Db\Command\CommandInterface::truncateTable()
Creates an SQL command for truncating a DB table.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface truncateTable ( string $table ) | ||
| $table | string |
The table to truncate. Note: The method will quote the |
public function truncateTable(string $table): static;
Defined in: Yiisoft\Db\Command\CommandInterface::update()
Creates an UPDATE command.
For example,
$connectionInterface->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
or with using parameter binding for the condition:
$minAge = 30;
$connectionInterface->createCommand()->update(
'user',
['status' => 1],
'age > :minAge',
[':minAge' => $minAge]
)->execute();
The method will escape the column names and bind the values to update.
Note that the created command isn't executed until you call {@see \Yiisoft\Db\Command\execute()}.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface 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 name of the table to update. |
| $columns | array |
The column data (name => value) to update. |
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string |
The condition to put in the WHERE part. Please refer to {@see \Yiisoft\Db\Command\QueryPartsInterface::where()} on how to specify condition. |
| $from | array|Yiisoft\Db\Expression\ExpressionInterface|string|null |
The FROM part. Please refer to {@see \Yiisoft\Db\Command\QueryPartsInterface::from()} on how to specify FROM part. |
| $params | array |
The parameters to bind to the command. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException |
Note: The method will quote the |
public function update(
string $table,
array $columns,
array|ExpressionInterface|string $condition = '',
array|ExpressionInterface|string|null $from = null,
array $params = [],
): static;
Defined in: Yiisoft\Db\Command\CommandInterface::upsert()
Creates a command 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 \Yiisoft\Db\Expression\Expression('visits + 1'),
],
$params,
);
The method will escape the table and column names.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface upsert ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true ) | ||
| $table | string |
The name of the table to insert rows into or update rows in. |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or an
instance of {@see \Yiisoft\Db\Query\QueryInterface} to perform |
| $updateColumns | array|boolean |
The column data (name => value) to update if it already exists.
If |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function upsert(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
): static;
Defined in: Yiisoft\Db\Command\CommandInterface::upsertReturning()
Creates a command to insert rows into a database table if they don't already exist (matching unique constraints) or update them if they do, returning values from the specified columns.
The method will quote the table, insertColumns, updateColumns and returnColumns parameters before using
it in the generated SQL.
See also upsertReturningPks().
| public abstract array upsertReturning ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, string[]|null $returnColumns = null ) | ||
| $table | string |
The name of the table to insert rows into or update rows in. |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or an
instance of {@see \Yiisoft\Db\Query\QueryInterface} to perform |
| $updateColumns | array|boolean |
The column data (name => value) to update if it already exists.
If |
| $returnColumns | string[]|null |
The column names to return values from. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function upsertReturning(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
?array $returnColumns = null,
): array;
Defined in: Yiisoft\Db\Command\CommandInterface::upsertReturningPks()
Creates a command to insert rows into a database table if they don't already exist (matching unique constraints) or update them if they do, with returning inserted or updated primary key values.
The method will quote the table, insertColumns and updateColumns parameters before using it in the
generated SQL.
See also upsertReturning().
| public abstract array upsertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true ) | ||
| $table | string |
The name of the table to insert rows into or update rows in. |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface |
The column data (name => value) to insert into the table or an
instance of {@see \Yiisoft\Db\Query\QueryInterface} to perform |
| $updateColumns | array|boolean |
The column data (name => value) to update if it already exists.
If |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
public function upsertReturningPks(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
): array;
Defined in: Yiisoft\Db\Command\CommandInterface::withDbTypecasting()
Returns copy of the instance with enabled or disabled typecasting of values when inserting or updating records.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface withDbTypecasting ( boolean $dbTypecasting = true ) | ||
| $dbTypecasting | boolean | |
public function withDbTypecasting(bool $dbTypecasting = true): static;
Defined in: Yiisoft\Db\Command\CommandInterface::withPhpTypecasting()
Returns a copy of the instance with enabled or disabled typecasting of values when retrieving records from DB.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface withPhpTypecasting ( boolean $phpTypecasting = true ) | ||
| $phpTypecasting | boolean | |
public function withPhpTypecasting(bool $phpTypecasting = true): static;
Defined in: Yiisoft\Db\Command\CommandInterface::withTypecasting()
Returns a copy of the instance with enabled or disabled typecasting of values when inserting, updating or retrieving records from DB.
| public abstract Yiisoft\Db\Driver\Pdo\PdoCommandInterface withTypecasting ( boolean $typecasting = true ) | ||
| $typecasting | boolean | |
public function withTypecasting(bool $typecasting = true): static;
Signup or Login in order to comment.