<i id='C3y5G'><tr id='C3y5G'><dt id='C3y5G'><q id='C3y5G'><span id='C3y5G'><b id='C3y5G'><form id='C3y5G'><ins id='C3y5G'></ins><ul id='C3y5G'></ul><sub id='C3y5G'></sub></form><legend id='C3y5G'></legend><bdo id='C3y5G'><pre id='C3y5G'><center id='C3y5G'></center></pre></bdo></b><th id='C3y5G'></th></span></q></dt></tr></i><div id='C3y5G'><tfoot id='C3y5G'></tfoot><dl id='C3y5G'><fieldset id='C3y5G'></fieldset></dl></div>
<legend id='C3y5G'><style id='C3y5G'><dir id='C3y5G'><q id='C3y5G'></q></dir></style></legend>

    <small id='C3y5G'></small><noframes id='C3y5G'>

  1. <tfoot id='C3y5G'></tfoot>
        <bdo id='C3y5G'></bdo><ul id='C3y5G'></ul>
    1. Doctrine2 和 Zend 框架中的多数据库连接

      时间:2023-05-30
      <legend id='tjOPY'><style id='tjOPY'><dir id='tjOPY'><q id='tjOPY'></q></dir></style></legend>

    2. <tfoot id='tjOPY'></tfoot>
        <bdo id='tjOPY'></bdo><ul id='tjOPY'></ul>
          <i id='tjOPY'><tr id='tjOPY'><dt id='tjOPY'><q id='tjOPY'><span id='tjOPY'><b id='tjOPY'><form id='tjOPY'><ins id='tjOPY'></ins><ul id='tjOPY'></ul><sub id='tjOPY'></sub></form><legend id='tjOPY'></legend><bdo id='tjOPY'><pre id='tjOPY'><center id='tjOPY'></center></pre></bdo></b><th id='tjOPY'></th></span></q></dt></tr></i><div id='tjOPY'><tfoot id='tjOPY'></tfoot><dl id='tjOPY'><fieldset id='tjOPY'></fieldset></dl></div>

          <small id='tjOPY'></small><noframes id='tjOPY'>

                <tbody id='tjOPY'></tbody>
                本文介绍了Doctrine2 和 Zend 框架中的多数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前正在开发一个使用 ZF 1.11.3 构建的应用程序 - Doctrine2 是所使用的 ORM 组件.我需要使用多个数据库.在 application.ini 文件中,我按如下方式设置了数据库连接:

                I am currently working on an application which is built using ZF 1.11.3 - Doctrine2 is the ORM component used. I need to use multiple databases. Within the application.ini file, I have set the database connections as follows:

                resources.doctrine.dbal.connections.default.parameters.dbname   = "db_name_one"
                resources.doctrine.dbal.connections.secondary.parameters.dbname   = "db_name_two"
                

                我如何将基于第二个数据库连接的 Doctrine2 实体类与该连接相关联:例如,如果我有一个来自第二个连接的实体类:

                How would I associate the Doctrine2 entity classes based on the second database connection with that connection: For example, if I have an entity class from the second connection as:

                /*
                   * @Entity
                   * @Table(name="tableOnSecondDatabase")
                   */
                  Class EntityFromSecond
                  {
                

                Doctrine2/ZF 如何知道哪些实体类映射到数据库?感谢您的帮助.

                How will Doctrine2/ZF know what entity classes are mapped to a database? Thanks for helping.

                推荐答案

                我不认为您可以将实体绑定到特定连接,这在 Doctrine 2 架构中没有意义.

                I don't thinl you can bind an entity to specific connection, it wouldn't make sense in the Doctrine 2 architecture.

                另一方面,您可以做的是拥有两个 EntityManager,每个都有不同的连接选项.您必须在业务逻辑中决定哪个实体由哪个连接管理器处理.

                What you can do, on the other hand is to have two EntityManagers, each with different connection options. You must decide in your business logic, which entity is treated by which connection manager.

                编辑 原则 2 不支持跨数据库连接,因为它具有两个不同的连接并跨它们连接,AFAIK.我什至无法想象,这将如何在 PHP PDO 级别上工作.Vijay 对基于 Doctrine 1 和第二个的建议的建议,这并不完全是跨数据库连接,因为 Doctrine 1 执行 2 个查询并合并结果本身,这在性能方面不是最佳的.

                edit Doctrine 2 does not support cross database joins in the sense of having two distinct connections and joining across them, AFAIK. I can't even imagine, how that would work on the PHP PDO level. What Vijay suggested for one based around Doctrine 1 and second, that's not exactly cross database join, as Doctrine 1 executes 2 queries and merges the results itself, which is not optimal performance-wise.

                另一方面,你可以做的是建立一个连接,它可以访问两个数据库(也就是说,如果它们在同一个数据库服务器上)或模式,如果你在说 Postgres,并定义您的实体:

                What you could do, on the other hand, is to have one connection, which can access both databases (that is, if they're on the same DB server), or schemas, if you're on say Postgres, and define your entities as such:

                //defining first entity
                @Entity
                @Table(firstSchema.table_name)
                class MyEntity
                
                //defining second entity
                
                @Entity
                @Table(secondSchema.table_name)
                class SecondEntity
                

                这应该可行,我相信

                这篇关于Doctrine2 和 Zend 框架中的多数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Zend Framework - 安装旧版本 下一篇:使用 Zend Mail 发送邮件时出现问题?

                相关文章

                • <bdo id='tsSoe'></bdo><ul id='tsSoe'></ul>
              • <small id='tsSoe'></small><noframes id='tsSoe'>

                  <i id='tsSoe'><tr id='tsSoe'><dt id='tsSoe'><q id='tsSoe'><span id='tsSoe'><b id='tsSoe'><form id='tsSoe'><ins id='tsSoe'></ins><ul id='tsSoe'></ul><sub id='tsSoe'></sub></form><legend id='tsSoe'></legend><bdo id='tsSoe'><pre id='tsSoe'><center id='tsSoe'></center></pre></bdo></b><th id='tsSoe'></th></span></q></dt></tr></i><div id='tsSoe'><tfoot id='tsSoe'></tfoot><dl id='tsSoe'><fieldset id='tsSoe'></fieldset></dl></div>
                1. <tfoot id='tsSoe'></tfoot>

                    <legend id='tsSoe'><style id='tsSoe'><dir id='tsSoe'><q id='tsSoe'></q></dir></style></legend>