简体   繁体   中英

Batch delete and batch update

http://www.yiiframework.com/doc-2.0/yii-db-command.html#delete()-detail

I see in the documentation a batch insert, but no batch delete or batch update. Is there a way to implement a batch update and delete using Yii's db API? What's the best way? I want to avoid using a loop and making several requests. Also, I am using Yii 1.0. I noticed there's no doc for 1.0, will those methods work in 1.0?

If you want to delete or update few rows you should use WHERE. No one make batch delete like this DELETE ... WHERE id=1; DELETE ... WHERE id=2; DELETE ... WHERE id=1; DELETE ... WHERE id=2; you can do it like this DELETE ... WHERE id IN(1,2);

Batch insert for Yii 1 is available only since 1.1.14.

$builder=Yii::app()->db->schema->commandBuilder;
$command=$builder->createMultipleInsertCommand('tbl_post', array( array('title' => 'record 1', 'text' => 'text1'), array('title' => 'record 2', 'text' => 'text2'), ));
$command->execute();

This is the doc for 1.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM