Home >Backend Development >PHP Tutorial >phalcon query skills

phalcon query skills

WBOY
WBOYOriginal
2016-07-29 09:13:051359browse

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);

2. Use model skillfully to update data in batches

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn