【问题标题】:how to use multiple database in symfony如何在 symfony 中使用多个数据库
【发布时间】:2011-09-30 06:58:07
【问题描述】:

我正在 symfony 中创建一个项目,但是当我的项目有两个数据库时,我突然遇到了麻烦:

all:  gapi_1:
class: sfDoctrineDatabase
param:
  dsn:      mysql:host=localhost;dbname=gapi_1
  username: root
  password:

 gapi_2:
class: sfDoctrineDatabase
param:
  dsn:      mysql:host=localhost;dbname=gapi_2
  username: root
  password:

我对如何在我的操作页面中访问数据库感到非常困惑。请帮助我在同一个 action.class.php 文件中访问 symfony 多个数据库。

【问题讨论】:

  • 你有没有看过这个帖子中给出的答案:stackoverflow.com/questions/733224/…
  • 感谢解决方案链接,我的数据库已成功创建,但我无法访问它们。所以,请帮我在 action.class.php 中访问这个数据库

标签: database symfony1


【解决方案1】:
Doctrine_Manager::getInstance()->setCurrentConnection('gapi_1');

Doctrine_Manager::getInstance()->setCurrentConnection('gapi_2');

在我认为的上下文之外(不确定):

$databaseManager = new sfDatabaseManager($this->configuration);
$db1 = $databaseManager->getDatabase('gapi_1');
$db1->getDoctrineConnection();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 2011-05-30
    • 2018-01-25
    • 2015-10-29
    • 2021-05-11
    相关资源
    最近更新 更多