php – 嵌套选择使用Zend Db

前端之家收集整理的这篇文章主要介绍了php – 嵌套选择使用Zend Db前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个查询
select empl.idemp,(select em.firstnm from tbl_employeemaster em where em.idemp = empl.approvedby) as approvedby from tbl_empleaveapplication empl
join tbl_employeemaster emp on empl.idemp = emp.idemp
join tbl_leavemaster lvm on empl.idleavemaster = lvm.idleavemaster

我需要使用zend db来构建这种类型的查询

以下是将字符串查询转换为Zend_Db_Select的方法
class Empleaveapplication extends Zend_Db_Table_Abstract
{
    protected $_name = 'tbl_empleaveapplication';
}

$table = new Empleaveapplication();

// create sub query
$subsql = $table->select()
                ->setIntegrityCheck(false)
                ->from(array('em' => 'tbl_employeemaster'),array('firstnm'))
                ->where('idemp = empl.approvedby','');

// main query
$sql = $table->select()
             ->setIntegrityCheck(false)
             ->from(array('empl' => 'tbl_empleaveapplication'),array('idemp','approvedby' => new Zend_Db_Expr('(' . $subsql . ')')))
             ->joinInner(array('emp' => 'tbl_employeemaster'),'empl.idemp = emp.idemp',array())
             ->joinInner(array('lvm' => 'tbl_leavemaster'),'empl.idleavemaster = lvm.idleavemaster',array());
原文链接:https://www.f2er.com/php/134850.html

猜你在找的PHP相关文章