yii\db\Migration::insert PHP Method

insert() public method

The method will properly escape the column names, and bind the values to be inserted.
public insert ( string $table, array $columns )
$table string the table that new rows will be inserted into.
$columns array the column data (name => value) to be inserted into the table.
    public function insert($table, $columns)
    {
        echo "    > insert into {$table} ...";
        $time = microtime(true);
        $this->db->createCommand()->insert($table, $columns)->execute();
        echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
    }

Usage Example

 /**
  * @inheritdoc
  */
 public function insert($table, $columns)
 {
     if ($table != '{{%auth_item}}' || !isset($columns['name'])) {
         return parent::insert($table, $columns);
     }
     $item = (new \yii\db\Query())->from($table)->where(['name' => $columns['name']])->exists();
     if (!$item) {
         return parent::insert($table, $columns);
     }
 }
All Usage Examples Of yii\db\Migration::insert