cakephp在查询中使用“OR”“AND”

时间:2013-06-28 08:45:46

标签: sql cakephp cakephp-2.0 cakephp-2.1

我是cakephp的新手所以我不知道如何在cakephp中编写此查询。有时我现在有这个查询

  $count = $this->User->find('count', array(
            'conditions' => array('User.mobileNo' => $mobileNo)));

此查询检查是否数据库中的手机号码等于用户给出的手机号码...我想添加另一个条件,即 手机号码等于用户提供的手机号码,电子邮件等于用户提供电子邮件的号码,例如

     $count = $this->User->find('count', array(
            'conditions' => array('User.mobileNo' => $mobileNo))) And
   'conditions' => array('User.email' => $email))) 

1 个答案:

答案 0 :(得分:3)

您只需添加条件数组:

$count = $this->User->find('count', array(
    'conditions' => array(
        'User.mobileNo' => $mobileNo,
        'User.email' => $email
    )
));

文档e.g.中有很多这样的例子。

$conditions = array("Post.title" => "This is a post", "Post.author_id" => 1);
// Example usage with a model:
$this->Post->find('first', array('conditions' => $conditions));