Home >Backend Development >PHP Tutorial >phalcon query skills
A brief introduction to a few tips for using phalcon to query
1. Use find and in to query, as follows:
$orderIdList = array_unique(array_map('intval',$orderIdList)); if ($orderIdList) { $orderList = ChildOrder::find([ 'conditions'=>'parents_id IN ({orderIdList:array})', 'bind'=>['orderIdList'=>$orderIdList] ]); }The $orderIdList here is an array. Using this query method, you can query something like this
select * from `childorder` where parents_id in ($orderIdList);
The object $orderList has been queried above. Next, you need to batch modify the value of a certain column in the object. You can do this
foreach($orderList as $row){ $row->state = 0; if ($row->save() == false) { foreach ($orderList->getMessages() as $message) { throw new \<strong>Exception</strong>('更新失败'); } } }. The effect of this is similar to
update `childorder` set state = 0 where parents_id in ($orderIdList);
The above introduces the phalcon query skills, including Exception content. I hope it will be helpful to friends who are interested in PHP tutorials.