Need lots of example of activeRecord Query

Dear all,

As beginner, there is no way I can learn to query AR by reading class reference and There is not enough demo to cover enough situations.

I want to check if user email and password matches (SELECT * FROM user WHERE = $email AND user.password = $password)

In the AR class:

$this->exists(array('email = :email', 'AND password =:password'), array(':email'=>$this->email, ':password'=>$this->password));

The above code won’t work. Can you tell me what is the right way to formulate this query?

You can use criteria like this


    'condition' => 'email = :email AND password =:password',

    'params' => array(





You can also read this:

If you meet a $condition parameter in any AR function, then it can be either a CDbCriteria instance or just it’s “condition” property (string).


OR even an array of initial values for constructing a CDbCriteria object (like in yangmls’s example).


The solution has been given in this post - http://www.yiiframew…dpost__p__90821

@nettrinity - there is no need to post the same question on different threads

I see. Sorry about the difficulties I caused to the forum due to repeating question. I was agitated by the frustration of not making a query right.