$query= Model::query()->leftjoin("Modules\Models\Entities\Contents\CmsContentArticle","[Modules\Models\Entities\Contents\CmsContent].id = CmsA.contentId","CmsA")->columns(array("[Modules\Models\Entities\Contents\CmsContent].title AS CmsContentTitle","[Modules\Models\Entities\Contents\CmsContent].id AS id","[Modules\Models\Entities\Contents\CmsContent].classId AS classId","CmsA.content"))->andWhere('[Modules\Models\Entities\Contents\CmsContent].disabled = 0');$queryResult=$query->bind($bindingInfo)->execute();
不分页 and 单表
$query= Model::query()->columns(array('id','name','expect_return'))->andWhere('category_frontend = :type:')->orderBy('id desc');$bindInfo['type']=$filterArray['type'];if(!empty($filterArray['name'])){$query->andWhere('name like :name:');$bindInfo['name']='%'.$filterArray['name'].'%';}$res=$query->bind($bindInfo)->execute();if($res){return$res->toArray();}else{returnnull;}
PHQL 查询
#方法1usePhalcon\Mvc\Model\Query;$query=newQuery("SELECT SUM(reward) AS nums FROM Modules\Models\Entities\AccountStatistics WHERE date = :date: AND type = :type:",$this->getDI());$cars=$query->execute(array('date'=>$date,'type'=>$type));#方法2$query=$this->modelsManager->createQuery("SELECT * FROM Cars WHERE name = :name:");$cars=$query->execute(array('name'=>'Audi'));#方法3$cars=$this->modelsManager->executeQuery("SELECT * FROM Cars WHERE name = :name:",array('name'=>'Audi'));
$accountStatistics= AccountStatistics::findFirst(array('conditions'=>'accountId = :accountId: and date = :date: and type = :type:','bind'=>array('accountId'=>$info['accountId'],'date'=>$info['date'],'type'=>$info['type'])));if($accountStatistics===false){returnfalse;}$keys=get_class_vars('Modules\Models\Entities\AccountStatistics');foreach($keysas$key=>$val){if(array_key_exists($key,$info)){$accountStatistics->$key=$info[$key];}}if($accountStatistics->save()){returntrue;}