Zend Db表三表JOIN

时间:2010-10-14 07:55:56

标签: php mysql zend-framework join

1. payment(user_id, calculation_id)
2. user(id, user_name)
3. calculation(id, period_start_date, period_end_date)

我需要paymentsuser_nameperiod_start_date选择period_end_date。如何在Zend Framework中的一个查询中完成?

非常感谢。

1 个答案:

答案 0 :(得分:11)

我找到了解决方案:

$db     = new Zend_Db_Table('payment');
$select = $db->select()->setIntegrityCheck(false);
$select->from('payment')
       ->join('user', 'user.id = payment.user_id', array('user_name'))
       ->join('calculation', 'calculation.id = payment.calculation_id', array('period_start_date', 'period_end_date'));

$payment = $db->fetchAll($select)->toArray();