当前位置:网站首页>Symfony 2: multiple and dynamic database connections

Symfony 2: multiple and dynamic database connections

2022-06-12 07:51:00 Rich in starch

problem :

I am quite new to SF2 and I was wondering how I could manage connections to severals databases into ONE bundle. I am a SF2 novice , I want to know how to manage several databases to ONE Bundled connections .For the moment I have this solution - which works fine - but I don't know if it is the right way to do it.... At present, I have this solution - Work well - But I don't know if this is the right way ....

in myBundle\\Ressource\\config\\config.yml : stay myBundle \\ Ressource \\ config \\ config.yml in :

doctrine:dbal:    default_connection:       default    connections:        default:            dbname:           SERVER            user:             root            password:         null            host:             localhost        client:            dbname:           CLIENT_134            user:             root            password:         null            host:             localhostorm:    default_entity_manager:   default    entity_managers:        default:            connection:       default            mappings:                MyBundle: ~        client:            connection:       client            mappings:                MyBundle: ~

And then, in order to switch to one of the BD or the other, I do : then , To switch to BD Or one of them , Be me :

$O_ressource=  $this->get('doctrine')->getEntityManager('client');$O_ressource=  $this->get('doctrine')->getEntityManager('default');

So guys, do you think it is a good way to manage this? So, guys , Do you think this is a good way to manage this ?

And my second question is : My second question is :

how to set up dynamic database connection? How to set up dynamic database connection ?I mean I have 100 databases in my system and I can't set all them in my config.yml file. I mean, my system has 100 A database , I can't be in config.yml Set them in the file .So I would like to be able to change database on the fly. So I want to be able to dynamically change the database .

Thanks for the help! Thank you for your help !


Solution :

Reference resources : https://stackoom.com/en/question/QtJf
原网站

版权声明
本文为[Rich in starch]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010554092374.html

随机推荐