简体   繁体   English

教义1.2-如何连接2个数据库

[英]Doctrine 1.2 - How to connect 2 databases

I have two databases on my server, I need to connect these two databases using Doctrine 1.2 so I use both as a single database, creating models and everything. 我的服务器上有两个数据库,我需要使用Doctrine 1.2连接这两个数据库,因此我将两者都用作一个数据库,同时创建模型和所有内容。

In my bootstrap.php file I have: 在我的bootstrap.php文件中,我有:

Doctrine_Manager::connection('mysql://safonizer-user:e41b74468b2c867f06759c5e7255c838@localhost/safonizer','padrao');
Doctrine_Manager::connection('mysql://safonizer-user:e41b74468b2c867f06759c5e7255c838@localhost/padraosaude','padrao1');

But does not work the way I want ... someone can help me do this? 但是无法按照我想要的方式工作...有人可以帮助我做到这一点吗? It has to do this and how? 它必须执行此操作以及如何执行?

Thank you in advance. 先感谢您。

Have you read the Doctrine 1.2 documentation on connections ? 您是否已阅读有关连接的Doctrine 1.2 文档 That makes two particular comments that you should consider (it's not clear from your "...does not work the way I want..." in your original question what problem you are encountering): 这给出了两个您应该考虑的特殊评论(在您最初遇到的问题中, 您的...无法按照我想要的方式工作...”尚不清楚):

  1. As per the documentation's "Current Connection" section, note that "The current connection is the last opened connection." 根据文档的“当前连接”部分,请注意“当前连接是最后打开的连接”。

  2. To change the current connection use Doctrine_Manager::setCurrentConnection() (in your case using padrao or pardrao1 as parameters). 要更改当前连接,请使用Doctrine_Manager::setCurrentConnection() (在您的情况下,使用padraopardrao1作为参数)。

If you are interested in queries that span the two databases, you should read the Doctrine 1.2 documentation on cross database joins . 如果您对跨越两个数据库的查询感兴趣,则应阅读有关跨数据库联接的Doctrine 1.2文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM