开发者

convert sql query to Zend DB query

开发者 https://www.devze.com 2023-04-01 21:04 出处:网络
I have tow table : article,sub_categories how to convert this query to zend Db query join $sql=\" SELECT article.*, sub_categories.name_arabic AS sub_category_开发者_Go百科name_arabic, sub_categorie

I have tow table : article,sub_categories how to convert this query to zend Db query join

$sql="

SELECT article.*, sub_categories.name_arabic AS sub_category_开发者_Go百科name_arabic, sub_categories.name_english AS sub_category_name_english, article.sub_category_id AS sub_categories_id FROM article LEFT JOIN sub_categories ON article.sub_category_id = sub_categories.id WHERE article.active = 1 ";

Please need help

Thanks with regard


This should do the trick:

$db->select()
   ->from('article', array('*', 'sub_categories_id' => 'sub_category_id')
   ->joinLeft(
        'sub_categories',
        'article.sub_category_id = sub_categories.id',
        array('sub_category_name_arabic' => 'name_arabic', 'sub_category_name_english' => 'name_english'))
   ->where('article.active = 1');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号