mysql query with Yii query builder

后端 未结 1 1124
囚心锁ツ
囚心锁ツ 2021-01-17 02:19

Hi is there any way to write below query in Yii query builder

        SELECT t.email
        FROM otz_user_header t
        JOIN otz_customers r ON t.user_id         


        
相关标签:
1条回答
  • 2021-01-17 02:27

    Yep, sure is. :-) Oh, you mean, how do you do it? ;-)

    Start here: http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder

    $emails = Yii::app()->db->createCommand()
        ->select('t.email')
        ->from('otz_user_header t')
        ->join('otz_customers r', 't.user_id = r.customer_user_id')
        … // some of this left out as an exercise for the reader
        ->where(
            array('and','r.rate_auto_approve=0'
                … // more left out here
                array('and',new CDbExpression('cr.rating_date < CURDATE()')),
            ),
        ),
        ->queryAll();
    

    The CDbExpression item hasn't been tested, but the rest should work fine. Note: take a look at the documentation on where syntax, it gets a bit tricky. In essence, every AND/OR becomes another array line nested inside your original where array.

    0 讨论(0)
提交回复
热议问题