[英]Dynamic database connection in Silex with Doctrine 2
我正在尝试执行与此帖子非常相似的操作- 动态数据库连接symfony2-但使用Silex。
我已经成功设置了我的基础数据库以及我想动态连接的数据库。
database:
base:
driver: pdo_sqlite
path: database/dev.sqlite
website:
driver: pdo_sqlite
path: ~
上面的内容读入$dbs_options
,然后使用以下内容进行配置:
$app -> register(new DoctrineServiceProvider, ['dbs.options' => $dbs_options]);
// configure the ORM identities
$app -> register(new DoctrineOrmServiceProvider, [
'orm.proxies_dir' => Utils::joinPaths($app -> config -> appRoot, 'running', 'proxies'),
'orm.em.options' => [
'mappings' => $mappings
]
]
);
// set up multiple entity managers and assign the base connection as default
$app['orm.ems.default'] = 'basedb';
$app['orm.ems.options'] = [
'basedb' => [
'connection' => 'base',
'mappings' => $app['orm.em.options']['mappings']
],
'websitedb' => [
'connection' => 'website',
'mappings' => $app['orm.em.options']['mappings']
]
];
在我的before
活动中,我能够成功地查询basedb
以获取我要连接的网站数据库的名称。
这就是我遇到的问题,我不知道并且无法找到如何在Silex中重新配置数据库连接。 有没有人做到这一点?
我在Silex中没有这样的请求,但是您可以随时使用
$conn = Doctrine\DBAL\DriverManager::getConnection($params, $config);
创建与数据库的连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.