TableGateway with multiple FROM tables

前端 未结 1 476
耶瑟儿~
耶瑟儿~ 2020-12-01 15:45

I would like to do a simple INNER JOIN between two tables in Zend2.

Concretely, I would like to do this in Zend2:

SELECT * FROM foo, bar W

相关标签:
1条回答
  • 2020-12-01 15:56

    I hope this will help you along your journey as this is a working example I have:

    namespace Pool\Model;
    
    use Zend\Db\TableGateway\AbstractTableGateway;
    use Zend\Db\Sql\Select;
    
    class IpaddressPool extends AbstractTableGateway
    {
        public function __construct($adapter)
        {
            $this->table = 'ipaddress_pool';
    
            $this->adapter = $adapter;
    
            $this->initialize();
        }
    
        public function Leases($poolid)
        {
            $result = $this->select(function (Select $select) use ($poolid) {
                $select
                    ->columns(array(
                        'ipaddress',
                        'accountid',
                        'productid',
                        'webaccountid'
                    ))
                    ->join('account', 'account.accountid = ipaddress_pool.accountid', array(
                        'firstname',
                        'lastname'
                    ))
                    ->join('product_hosting', 'product_hosting.hostingid = ipaddress_pool.hostingid', array(
                        'name'
                    ))
                    ->join('webaccount', 'webaccount.webaccountid = ipaddress_pool.webaccountid', array(
                        'domain'
                    ))->where->equalTo('ipaddress_pool.poolid', $poolid);
            });
    
            return $result->toArray();
        }
    }
    
    0 讨论(0)
提交回复
热议问题