Loading…

How to use delete(), insert() and save() methods in YII2?

1. delete()

$connection->createCommand()->delete('tbl_user', 'status = 1') ->execute();

2. save()

$model = new Admin;
$model->name = 'YII2';
$model->email = 'admin@bestinterviewquestion.com';
$model->save(); // this is equivalent to $model->insert();

3. insert()

$connection->createCommand()->insert('tbl_user',
[
'name' => 'yii',
'status' => 1,
])
->execute();

 

Suggest An Answer

No suggestions avaliable!

Latest post from Yii 2 interview questions

Ask Question