给出一个查询:
SELECT t1.c1, t2.c1 FROM t1,t2;
如何在不使用连接的情况下在Zend框架中编写它?
答案 0 :(得分:0)
在zend框架中尝试以下连接查询,
$sql = $this->tableGateway->getSql()->select();
$sql->join('table2', "table1.column1 = table2.column1", array(column1,column2), 'inner');
答案 1 :(得分:0)
假设您有一个公共字段(我们称之为c2
),您可以执行近似JOIN
的操作而不会实际执行JOIN
。
// we'll assume $adapter is an instance of Zend_Db_Adapter_Mysqli
$cols = $adapter->fetchAll(
'
SELECT
t1.c1 AS t1c1,
t2.c1 AS t2c1
FROM t1, t2
WHERE t1.c2 = t2.c2
'
);
使用Zend_Db_Select
你可以这样做
$rows = $adapter->select()
->from('t1', array('t1c1' => 'c1'))
->from('t2', array('t2c1' => 'c1'))
->where('t1.c2 = t2.c2')
->query()->fetchAll();