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
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