yii\db\Migration::update PHP Method

update() public method

The method will properly escape the column names and bind the values to be updated.
public update ( string $table, array $columns, array | string $condition = '', array $params = [] )
$table string the table to be updated.
$columns array the column data (name => value) to be updated.
$condition array | string the conditions that will be put in the WHERE part. Please refer to [[Query::where()]] on how to specify conditions.
$params array the parameters to be bound to the query.
    public function update($table, $columns, $condition = '', $params = [])
    {
        echo "    > update {$table} ...";
        $time = microtime(true);
        $this->db->createCommand()->update($table, $columns, $condition, $params)->execute();
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function update($table, $columns, $condition = '', $params = [])
 {
     $table = $this->autoWrappedTableName($table);
     return parent::update($table, $columns, $condition, $params);
 }