zf2 make a join between two different databases

后端 未结 5 1934
感情败类
感情败类 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:49

    The issue is occurring because of the way the Select class escapes quotes.

    $select->join("database2.table2", "database2.table2.id = table.id")

    Is rendered as:

    SELECT 'table'.* 'database2.table2'.* FROM 'table' INNER JOIN 'database2.table2' ON 'database2'.'table2'.'id' = 'table'.'id'

    Note the inconsistant and incorrect quoting around "database2.table2".

    Updating lines 596, 599, 624, 625 in \Zend\Db\Sql\Select to replace the "quoteIdentifier" method with "quoteIdentifierInFragment" renders the query correctly and allows a cross database join to be performed.

    I've submitted an issue report to Zend as I don't believe the current behaviour is intended so hopefully it will be updated in a future build. For now it's easy enough (though admittedly a little dirty) to update the class manually.

    https://github.com/zendframework/zf2/issues/4307

提交回复
热议问题