简要介绍几个使用phalcon查询的小技巧
1.使用find,和in来查询,如下:
$orderIdList = array_unique(array_map('intval',$orderIdList)); if ($orderIdList) { $orderList = ChildOrder::find([ 'conditions'=>'parents_id IN ({orderIdList:array})', 'bind'=>['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 \<strong>Exception</strong>('更新失败'); } } }
update `childorder` set state = 0 where parents_id in ($orderIdList);
以上就介绍了phalcon查询技巧,包括了Exception方面的内容,希望对PHP教程有兴趣的朋友有所帮助。