Zend如何创建左连接

时间:2011-02-10 09:48:33

标签: sql zend-framework join

如何关闭此左连接查询:

select advertisercontest.*, advertiseraccount.advertiserid, advertiseraccount.companyname
from advertisercontest
left join advertiseraccount on advertiseraccount.loginid = advertisercontest.loginid 
where advertisercontest.golive is not NULL;

进入Zend的左连接?

1 个答案:

答案 0 :(得分:22)

你可以这样做:

    $db = Zend_Db_Table::getDefaultAdapter();

    $select = $db->select();
    $select->from('advertisercontest', '*')
            ->joinLeft(
                    'advertiseraccount',
                    'advertiseraccount.loginid = advertisercontest.loginid',
                    array('advertiseraccount.advertiserid', 'advertiseraccount.companyname')
                    )
            ->where('advertisercontest.golive is not NULL');;

    $result = $db->fetchAll($select);

    var_dump($result);

这是Zend_Db_Select documentation