简体   繁体   English

批量删除和批量更新

[英]Batch delete and batch update

http://www.yiiframework.com/doc-2.0/yii-db-command.html#delete()-detail 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? 有没有一种方法可以使用Yii的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. 另外,我正在使用Yii 1.0。 I noticed there's no doc for 1.0, will those methods work in 1.0? 我注意到没有1.0的文档,这些方法是否可以在1.0中使用?

If you want to delete or update few rows you should use WHERE. 如果要删除或更新几行,则应使用WHERE。 No one make batch delete like this DELETE ... WHERE id=1; DELETE ... WHERE id=2; 没有人像这样的批量删除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); 您可以这样做DELETE ... WHERE id IN(1,2);

Batch insert for Yii 1 is available only since 1.1.14. 从1.1.14版本开始,Yii 1的批量插入功能才可用。

$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 这是1.0文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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