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
Looks like this question was asked a while back, but I seem to have found a good workaround or solution. If you utilize the Zend\Db\Sql\TableIdentifier and Zend\Db\Sq\Expression, you will be able to get around your issue.
public function getSelect(Hierarchy $hierarchy) {
$select = $this->tableGateway->getSql()->select();
$select->where(array('level' => $hierarchy()->getId()));
$select->join(
array('h' => new TableIdentifier('hierarchies', 'admin')),
new Expression('h.id = ?', 'users.idHierarchy', Expression::TYPE_IDENTIFIER),
array('hierarchyId' => 'id', 'level' => 'level')
);
return $select;
}
I wasn't sure which database your hierarchies table is in so I used 'admin' for now. YOu can replace it with which ever database name you have. See if it works for you, seems to work nicely for me.