zf2 make a join between two different databases

后端 未结 5 1913
感情败类
感情败类 2021-01-13 16:31

I am trying to make a join between two tables placed in different databases with Zend Framework 2.

The first table is called users and is stored in

5条回答
  •  庸人自扰
    2021-01-13 16:58

    Why you're using DAO concept? Only in a table gateway you'll have all of you'll need. You already have adapters in global or local.php. You already have factories for table gateways, haven't you? Why you need to pass Hierarchy class (I think it is another table gateway) to the current class? To do the join that you want, the only thing that you need is table identifier.

    $table2 = new Zend\Db\Sql\TableIdentifier('table2', 'schema_name'); 
    $select = $this->tableGateway->getSql()->select()
    ->join($table2, 'table1.field = table2.field', ['fields_from_table2'], 'INNER');
    
    $sql = new Sql($this->tableGateway->getAdapter());
    $selectString = $sql->buildSqlString($select);
    $result = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
    

    See the answer for this question

提交回复
热议问题