phalcon 查询

 1.简单查询
   $conditions = 'status = :status:';
    $parameters = [
        'status' => 1,
    ];
   $result = Customer::find(["columns"=> "id,name,status",  $conditions, 'bind' => $parameters]);
    2.含有like的查询
    $search = '小明';
    $models = Customer::query()
            ->where('id = :id:', array('id' => 10))
            ->andWhere('name LIKE :name:', $parameters = [ 'name' => '%'. $search. '%'])
            ->orderBy('date desc')
            ->execute()
            ->toArray();    
     3.连表查询 
      $model =$this->modelsManager->createBuilder()
        ->addfrom('app\models\service\Customer','a')
        ->leftJoin('app\models\product\Product', 'a.id = t.customer_id', 't')
        ->where('a.id = :id:', array('id' => '1'))
        ->groupBy(array('a.id'))
        ->getQuery()
        ->execute();

你可能感兴趣的:(php)