LEFT JOIN in ZF2 using TableGateway

前端 未结 7 1757
无人共我
无人共我 2021-01-03 23:01

I have a table:

*CREATE TABLE IF NOT EXISTS `blogs_settings` (
  `blog_id` int(11) NOT NULL AUTO_INCREMENT,
  `owner_id` int(11) NOT NULL,
  `title` varchar(         


        
7条回答
  •  情话喂你
    2021-01-03 23:12

    This is the exact need for both Join and Where clauses with tableGateway.

    public function getEmployeefunctionDetails($empFunctionId) {
        $empFunctionId = ( int ) $empFunctionId;
        //echo '
    '; print_r($this->tableGateway->getTable()); exit;
        $where = new Where();
        $where->equalTo('FUNCTION_ID', $empFunctionId);
    
        $sqlSelect = $this->tableGateway->getSql()->select()->where($where);    
    
        $sqlSelect->columns(array('FUNCTION_ID'));
        $sqlSelect->join('DEPARTMENTS', 'DEPARTMENTS.DEPARTMENT_ID = EMPLOYEE_FUNCTIONS.DEPARTMENT_ID', array('DEPARTMENT_ID','DEPARTMENT_NAME'), 'inner');
        $sqlSelect->join('ROLES', 'ROLES.ROLE_ID = EMPLOYEE_FUNCTIONS.ROLE_ID', array('ROLE_ID','ROLE_NAME'), 'inner');
    
        //echo $sqlSelect->getSqlString(); exit;
        $resultSet = $this->tableGateway->selectWith($sqlSelect);
    
        if (! $resultSet) {
            throw new \Exception ( "Could not find row $empFunctionId" );
        }
        return $resultSet->toArray();
    }
    

提交回复
热议问题