开发者

how to use multiple database in symfony

开发者 https://www.devze.com 2023-04-10 04:56 出处:网络
I\'m creating a project in symfony, but suddenly I\'m having trouble when there are two databases for my project like this:

I'm creating a project in symfony, but suddenly I'm having trouble when there are two databases for my project like this:

all:  gapi_1:
class: sfDoctrineDatabase
param:
  dsn:      mysql:host=localhost;dbna开发者_StackOverflow中文版me=gapi_1
  username: root
  password:

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

I'm very confused about how to access database in my action pages. Please help me to access the symfony multiple database in same action.class.php file.


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

and

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

outside of the context i think like that (not sure):

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

精彩评论

暂无评论...
验证码 换一张
取 消