Yii Framework 2.0 Insert Query

save() OR insert()

$model = new User;
$model->name = 'YII';
$model->email = 'yii2@framework.com';
$model->save();  // equivalent to $model->insert();

insert() command

	->insert('tbl_user', [
			'name' => 'yii',
			'status' => 1,])


Insert multiple rows at once using batchInsert() function.

$connection	->createCommand()
			->batchInsert('tbl_user', ['name', 'status'], 
				['Bala', 1],
				['Akilan', 0],
				['Babu', 1],
  • someone

    how to move data from one table to another by using clickable button?help me plsss

  • Anil Kumar Verma

    Behaviors are not working with batch insert.
    But when I use save() then behaviours working fine.
    Please help.

    • Soju Thomas

      behaviours works only for active records.