Home > Backend Development > PHP Tutorial > phalcon query skills

phalcon query skills

WBOY
Release: 2016-07-29 09:13:05
Original
1361 people have browsed it

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]
			]);
		}
Copy after login
The $orderIdList here is an array. Using this query method, you can query something like this
select * from `childorder` where parents_id in ($orderIdList);
Copy after login

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>('更新失败');
				}
			}
		}
Copy after login
. The effect of this is similar to
update `childorder` set state = 0 where parents_id in ($orderIdList);
Copy after login

The above introduces the phalcon query skills, including Exception content. I hope it will be helpful to friends who are interested in PHP tutorials.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template