时间:2021-07-01 10:21:17 帮助过:78人阅读
1.使用find,和in来查询,如下:
$orderIdList = array_unique(array_map('intval',$orderIdList));
if ($orderIdList) {
$orderList = ChildOrder::find([
'conditions'=>'parents_id IN ({orderIdList:array})',
'bind'=>['orderIdList'=>$orderIdList]
]);
}这里的$orderIdList是一个数组,使用这种查询方式就查询出类似这样的效果select * from `childorder` where parents_id in ($orderIdList);
上面已经查询出对象$orderList,接下来要批量修改对象中的某一列的值,可以这样做
foreach($orderList as $row){
$row->state = 0;
if ($row->save() == false) {
foreach ($orderList->getMessages() as $message) {
throw new \Exception('更新失败');
}
}
}这样做效果类似于update `childorder` set state = 0 where parents_id in ($orderIdList);
以上就介绍了phalcon查询技巧,包括了Exception方面的内容,希望对PHP教程有兴趣的朋友有所帮助。