zend_db_select使用3个或更多表连接

时间:2011-02-07 03:13:26

标签: php mysql zend-framework join zend-db-select

所以Zend_db_select有方法

  `joinUsing(table, join, [columns]) and joinInnerUsing(table, join, [columns])`

  `joinLeftUsing(table, join, [columns])`

  `joinRightUsing(table, join, [columns])`

  `joinFullUsing(table, join, [columns])`

但是如果你想加入3个或更多的表(例如,多对多的关联)会怎么样......例如:这个查询:

 SELECT * FROM (j LEFT JOIN e ON j.id = e.eee) LEFT JOIN w ON w.www = e.id

你将如何使用zend_db_select

进行此操作

2 个答案:

答案 0 :(得分:0)

尝试使用子查询和Zend_Db_Expr。阅读更多here

答案 1 :(得分:0)

尝试做...但我不太确定使用两个字段,但没有尝试使用3个字段

$dbmodel->select(false)
    ->setIntegrityCheck(false)
    ->from(array('t1' => 'table1'))
    ->joinLeft(array('t2' => 'table2'),                                             
        't1.somefeild = t2.somefeild')
    ->joinLeft(array('t3' => 'table3'),                                             
        't2.somefeild = t3.somefeild')

您尝试构建查询,还可以按die((string)$select)

检查查询