Свойство | Тип | Описание | |
---|---|---|---|
$db | the DB connection that this command is associated with | ||
$fetchMode | the default fetch mode for this command. | ||
$params | the parameters (name => value) that are bound to the current PDO statement. This property is maintained by methods such as Command::bindValue. It is mainly provided for logging purpose and is used to generate [[rawSql]]. Do not modify it directly. | ||
$pdoStatement | the PDOStatement object that this command is associated with | ||
$queryCacheDependency | the dependency to be associated with the cached query result for this command | ||
$queryCacheDuration | the default number of seconds that query results can remain valid in cache. Use 0 to indicate that the cached data will never expire. And use a negative number to indicate query cache should not be used. |
Метод | Описание | |
---|---|---|
addColumn ( string $table, string $column, string $type ) | Creates a SQL command for adding a new DB column. | |
addCommentOnColumn ( string $table, string $column, string $comment ) | Builds a SQL command for adding comment to column | |
addCommentOnTable ( string $table, string $comment ) | Builds a SQL command for adding comment to table | |
addForeignKey ( string $name, string $table, string | array $columns, string $refTable, string | array $refColumns, string $delete = null, string $update = null ) | Creates a SQL command for adding a foreign key constraint to an existing table. | |
addPrimaryKey ( string $name, string $table, string | array $columns ) | Creates a SQL command for adding a primary key constraint to an existing table. | |
alterColumn ( string $table, string $column, string $type ) | Creates a SQL command for changing the definition of a column. | |
batchInsert ( string $table, array $columns, array $rows ) | Creates a batch INSERT command. | |
bindParam ( string | integer $name, mixed &$value, integer $dataType = null, integer $length = null, mixed $driverOptions = null ) | Binds a parameter to the SQL statement to be executed. | |
bindValue ( string | integer $name, mixed $value, integer $dataType = null ) | Binds a value to a parameter. | |
bindValues ( array $values ) | Binds a list of values to the corresponding parameters. | |
cache ( integer $duration = null, yii\caching\Dependency $dependency = null ) | Enables query cache for this command. | |
cancel ( ) | Cancels the execution of the SQL statement. | |
checkIntegrity ( boolean $check = true, string $schema = '', string $table = '' ) | Builds a SQL command for enabling or disabling integrity check. | |
createIndex ( string $name, string $table, string | array $columns, boolean $unique = false ) | Creates a SQL command for creating a new index. | |
createTable ( string $table, array $columns, string $options = null ) | Creates a SQL command for creating a new DB table. | |
delete ( string $table, string | array $condition = '', array $params = [] ) | Creates a DELETE command. | |
dropColumn ( string $table, string $column ) | Creates a SQL command for dropping a DB column. | |
dropCommentFromColumn ( string $table, string $column ) | Builds a SQL command for dropping comment from column | |
dropCommentFromTable ( string $table ) | Builds a SQL command for dropping comment from table | |
dropForeignKey ( string $name, string $table ) | Creates a SQL command for dropping a foreign key constraint. | |
dropIndex ( string $name, string $table ) | Creates a SQL command for dropping an index. | |
dropPrimaryKey ( string $name, string $table ) | Creates a SQL command for removing a primary key constraint to an existing table. | |
dropTable ( string $table ) | Creates a SQL command for dropping a DB table. | |
execute ( ) : integer | Executes the SQL statement. | |
getRawSql ( ) : string | Returns the raw SQL by inserting parameter values into the corresponding placeholders in [[sql]]. | |
getSql ( ) : string | Returns the SQL statement for this command. | |
insert ( string $table, array $columns ) | Creates an INSERT command. | |
noCache ( ) | Disables query cache for this command. | |
prepare ( boolean $forRead = null ) | Prepares the SQL statement to be executed. | |
query ( ) : |
Executes the SQL statement and returns query result. | |
queryAll ( integer $fetchMode = null ) : array | Executes the SQL statement and returns ALL rows at once. | |
queryColumn ( ) : array | Executes the SQL statement and returns the first column of the result. | |
queryOne ( integer $fetchMode = null ) : array | false | Executes the SQL statement and returns the first row of the result. | |
queryScalar ( ) : string | null | false | Executes the SQL statement and returns the value of the first column in the first row of data. | |
renameColumn ( string $table, string $oldName, string $newName ) | Creates a SQL command for renaming a column. | |
renameTable ( string $table, string $newName ) | Creates a SQL command for renaming a DB table. | |
resetSequence ( string $table, mixed $value = null ) | Creates a SQL command for resetting the sequence value of a table's primary key. | |
setSql ( string $sql ) | Specifies the SQL statement to be executed. | |
truncateTable ( string $table ) | Creates a SQL command for truncating a DB table. | |
update ( string $table, array $columns, string | array $condition = '', array $params = [] ) | Creates an UPDATE command. |
Метод | Описание | |
---|---|---|
bindPendingParams ( ) | Binds pending parameters that were registered via Command::bindValue and Command::bindValues. | |
queryInternal ( string $method, integer $fetchMode = null ) : mixed | Performs the actual DB query of a SQL statement. | |
refreshTableSchema ( ) | Refreshes table schema, which was marked by Command::requireTableSchemaRefresh | |
requireTableSchemaRefresh ( string $name ) | Marks a specified table schema to be refreshed after command execution. |
public addColumn ( string $table, string $column, string $type ) | ||
$table | string | the table that the new column will be added to. The table name will be properly quoted by the method. |
$column | string | the name of the new column. The name will be properly quoted by the method. |
$type | string | the column type. [[\yii\db\QueryBuilder::getColumnType()]] will be called to convert the give column type to the physical one. For example, `string` will be converted as `varchar(255)`, and `string not null` becomes `varchar(255) not null`. |
public addCommentOnColumn ( string $table, string $column, string $comment ) | ||
$table | string | the table whose column is to be commented. The table name will be properly quoted by the method. |
$column | string | the name of the column to be commented. The column name will be properly quoted by the method. |
$comment | string | the text of the comment to be added. The comment will be properly quoted by the method. |
public addCommentOnTable ( string $table, string $comment ) | ||
$table | string | the table whose column is to be commented. The table name will be properly quoted by the method. |
$comment | string | the text of the comment to be added. The comment will be properly quoted by the method. |
public addForeignKey ( string $name, string $table, string | array $columns, string $refTable, string | array $refColumns, string $delete = null, string $update = null ) | ||
$name | string | the name of the foreign key constraint. |
$table | string | the table that the foreign key constraint will be added to. |
$columns | string | array | the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas. |
$refTable | string | the table that the foreign key references to. |
$refColumns | string | array | the name of the column that the foreign key references to. If there are multiple columns, separate them with commas. |
$delete | string | the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |
$update | string | the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |
public addPrimaryKey ( string $name, string $table, string | array $columns ) | ||
$name | string | the name of the primary key constraint. |
$table | string | the table that the primary key constraint will be added to. |
$columns | string | array | comma separated string or array of columns that the primary key will consist of. |
public alterColumn ( string $table, string $column, string $type ) | ||
$table | string | the table whose column is to be changed. The table name will be properly quoted by the method. |
$column | string | the name of the column to be changed. The name will be properly quoted by the method. |
$type | string | the column type. [[\yii\db\QueryBuilder::getColumnType()]] will be called to convert the give column type to the physical one. For example, `string` will be converted as `varchar(255)`, and `string not null` becomes `varchar(255) not null`. |
public bindParam ( string | integer $name, mixed &$value, integer $dataType = null, integer $length = null, mixed $driverOptions = null ) | ||
$name | string | integer | parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form `:name`. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. |
$value | mixed | the PHP variable to bind to the SQL statement parameter (passed by reference) |
$dataType | integer | SQL data type of the parameter. If null, the type is determined by the PHP type of the value. |
$length | integer | length of the data type |
$driverOptions | mixed | the driver-specific options |
protected bindPendingParams ( ) |
public bindValue ( string | integer $name, mixed $value, integer $dataType = null ) | ||
$name | string | integer | Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form `:name`. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. |
$value | mixed | The value to bind to the parameter |
$dataType | integer | SQL data type of the parameter. If null, the type is determined by the PHP type of the value. |
public bindValues ( array $values ) | ||
$values | array | the values to be bound. This must be given in terms of an associative array with array keys being the parameter names, and array values the corresponding parameter values, e.g. `[':name' => 'John', ':age' => 25]`. By default, the PDO type of each value is determined by its PHP type. You may explicitly specify the PDO type by using an array: `[value, type]`, e.g. `[':name' => 'John', ':profile' => [$profile, \PDO::PARAM_LOB]]`. |
public cache ( integer $duration = null, yii\caching\Dependency $dependency = null ) | ||
$duration | integer | the number of seconds that query result of this command can remain valid in the cache. If this is not set, the value of [[Connection::queryCacheDuration]] will be used instead. Use 0 to indicate that the cached data will never expire. |
$dependency | yii\caching\Dependency | the cache dependency associated with the cached query result. |
public createIndex ( string $name, string $table, string | array $columns, boolean $unique = false ) | ||
$name | string | the name of the index. The name will be properly quoted by the method. |
$table | string | the table that the new index will be created for. The table name will be properly quoted by the method. |
$columns | string | array | the column(s) that should be included in the index. If there are multiple columns, please separate them by commas. The column names will be properly quoted by the method. |
$unique | boolean | whether to add UNIQUE constraint on the created index. |
public createTable ( string $table, array $columns, string $options = null ) | ||
$table | string | the name of the table to be created. The name will be properly quoted by the method. |
$columns | array | the columns (name => definition) in the new table. |
$options | string | additional SQL fragment that will be appended to the generated SQL. |
public delete ( string $table, string | array $condition = '', array $params = [] ) | ||
$table | string | the table where the data will be deleted from. |
$condition | string | array | the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition. |
$params | array | the parameters to be bound to the command |
public dropColumn ( string $table, string $column ) | ||
$table | string | the table whose column is to be dropped. The name will be properly quoted by the method. |
$column | string | the name of the column to be dropped. The name will be properly quoted by the method. |
public dropCommentFromColumn ( string $table, string $column ) | ||
$table | string | the table whose column is to be commented. The table name will be properly quoted by the method. |
$column | string | the name of the column to be commented. The column name will be properly quoted by the method. |
public dropCommentFromTable ( string $table ) | ||
$table | string | the table whose column is to be commented. The table name will be properly quoted by the method. |
public dropForeignKey ( string $name, string $table ) | ||
$name | string | the name of the foreign key constraint to be dropped. The name will be properly quoted by the method. |
$table | string | the table whose foreign is to be dropped. The name will be properly quoted by the method. |
public dropPrimaryKey ( string $name, string $table ) | ||
$name | string | the name of the primary key constraint to be removed. |
$table | string | the table that the primary key constraint will be removed from. |
public query ( ) : |
||
Результат | the reader object for fetching the query result |
public queryAll ( integer $fetchMode = null ) : array | ||
$fetchMode | integer | the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) for valid fetch modes. If this parameter is null, the value set in [[fetchMode]] will be used. |
Результат | array | all rows of the query result. Each array element is an array representing a row of data. An empty array is returned if the query results in nothing. |
public queryColumn ( ) : array | ||
Результат | array | the first column of the query result. Empty array is returned if the query results in nothing. |
protected queryInternal ( string $method, integer $fetchMode = null ) : mixed | ||
$method | string | method of PDOStatement to be called |
$fetchMode | integer | the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) for valid fetch modes. If this parameter is null, the value set in [[fetchMode]] will be used. |
Результат | mixed | the method execution result |
public queryOne ( integer $fetchMode = null ) : array | false | ||
$fetchMode | integer | the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) for valid fetch modes. If this parameter is null, the value set in [[fetchMode]] will be used. |
Результат | array | false | the first row (in terms of an array) of the query result. False is returned if the query results in nothing. |
public queryScalar ( ) : string | null | false | ||
Результат | string | null | false | the value of the first column in the first row of the query result. False is returned if there is no value. |
protected refreshTableSchema ( ) |
public renameColumn ( string $table, string $oldName, string $newName ) | ||
$table | string | the table whose column is to be renamed. The name will be properly quoted by the method. |
$oldName | string | the old name of the column. The name will be properly quoted by the method. |
$newName | string | the new name of the column. The name will be properly quoted by the method. |
public renameTable ( string $table, string $newName ) | ||
$table | string | the table to be renamed. The name will be properly quoted by the method. |
$newName | string | the new table name. The name will be properly quoted by the method. |
protected requireTableSchemaRefresh ( string $name ) | ||
$name | string | name of the table, which schema should be refreshed. |
public resetSequence ( string $table, mixed $value = null ) | ||
$table | string | the name of the table whose primary key sequence will be reset |
$value | mixed | the value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have a value 1. |
public truncateTable ( string $table ) | ||
$table | string | the table to be truncated. The name will be properly quoted by the method. |
public update ( string $table, array $columns, string | array $condition = '', array $params = [] ) | ||
$table | string | the table to be updated. |
$columns | array | the column data (name => value) to be updated. |
$condition | string | array | the condition that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify condition. |
$params | array | the parameters to be bound to the command |
public $params |
public $pdoStatement |
public $queryCacheDependency |