Symfony2 - 运行时的动态守则数据库连接 [英] Symfony2 - Dynamic Doctrine Database Connections at Runtime

查看:92
本文介绍了Symfony2 - 运行时的动态守则数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个很好的解决方案,使用Symfony中的数据库实时管理实体管理。

I am looking for a good solution to on-the-fly connection of databases within Symfony utilizing Doctrine for entity management.

我的情况是所有入站用户对我们的服务将访问* .website.com地址,如client1.website.com。

The scenario I have is that all inbound users to our service will be visiting *.website.com addresses, like client1.website.com.

我们希望为客户端表使用一个Doctrine实体查看他们的数据库凭据,基于他们帐户的URL即时通讯。

We would like to use one Doctrine entity for the Client table to then look up their database credentials based on the URL of their account on the fly.

到目前为止,我已经在stackoverflow上找到了以下主题,讨论动态更改数据库凭据 - 但是没有明确的可行解决方案。

So far I have found the following topics here on stackoverflow that discuss dynamically changing the database credentials--but no clear workable solutions.

我想提出合作来组织一个工作的解决方案,我将为其他人组织一个博客/教程文章寻求修改Symfony中的数据库连接参数。

I'd like to propose collaborating to put together a working solution, and I'll put together a blog/tutorial post for other folks looking to modify database connection parameters within Symfony.

这是一些相关的帖子:

动态数据库连接symfony2

Symfony2,动态DB连接/ Doctrine服务的早期覆盖

谢谢!

推荐答案

如果$ em是现有的实体管理器,并且您想要重用它的配置,可以使用:

If $em is existing entity manager and you want to reuse it's configuration, you can use this:

$conn = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'root',
    'password' => '',
    'dbname'   => 'foo'
);

$new = \Doctrine\ORM\EntityManager::create(
    $conn,
    $em->getConfiguration(),
    $em->getEventManager()
);

这篇关于Symfony2 - 运行时的动态守则数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆