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 http://www.yiiframework.com/doc/guide/1.1/en/database.ar. There is not enough demo to cover enough situations.

I want to check if user email and password matches (SELECT * FROM user WHERE user.email = $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





$this->exists(array(

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

    'params' => array(

        ':email'=>$this->email,

        ':password'=>$this->password

    ),

));




You can also read this: http://www.yiiframework.com/doc/api/1.1/CDbCriteria#condition-detail

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).

update:

OR even an array of initial values for constructing a CDbCriteria object (like in yangmls’s example). http://www.yiiframework.com/doc/api/1.1/CDbCommandBuilder#createCriteria-detail

Thanks!

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.