是否有任何 PHP 框架(例如 CodeIgniter)支持基于每个用户帐户的数据库连接以在多租户数据库中使用?
我正在考虑开发一个多租户 SaaS 应用程序,我发现几个站点描述了使用tenantID 和可更新视图来分离数据的可靠方法。例如 这篇博文
这一切都取决于能否从主用户表对用户帐户进行身份验证,然后让其各自的数据库连接使用这些用户特定的凭据。这样,视图可以提取用户 ID 并将其映射到租户 ID 以显示该用户的视图。然而,大多数 PHP 框架在数据库连接(存储在文本配置文件中)方面往往非常静态。他们似乎有矛盾。
有谁知道: a) 如何让 CodeIgniter 优雅地处理这个问题? b) 可能有不同的 PHP 框架?
I'm looking into developing a multi-tenant SaaS application, and I found several sites that describe a solid way to separate the data using tenantIDs and updateable views. e.g. This blog post
It all hinges on the ability to have your user accounts authenticated from a master users table and then having their respective database connections use those user-specific credentials. This way, the views can pull the userid and map it to the tenantID to display that user's view. However, most PHP frameworks tend to be very static when it comes to database connections (stored in text config files). They appear to be at odds.
Does anyone know:
a) how to make CodeIgniter handle this gracefully?
b) a different PHP framework that might?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在非常基本的水平上,你可以这样做:
http://philsturgeon.co.uk/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up
根据需要扩展它,或将逻辑移至 MY_Controller 中以获得更大的灵活性。
At a horrendously basic level you can do this:
http://philsturgeon.co.uk/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up
Expand it as required, or move the logic into MY_Controller for more flexibility.
Code Igniter 论坛上有一个讨论此问题的主题。
http://codeigniter.com/forums/viewthread/165227/#846845
看起来就像您在配置文件中将用户数据库设置为主数据库一样,然后根据该用户数据库中的信息为该用户的新连接生成一个配置数组。所以,我想您至少需要将数据库名称存储在用户数据库中。
但不确定这有多好,因为我还没有机会尝试。
很抱歉,如果这不完全是您想要的,但它应该让您了解 Code Igniter 方法。
There is a topic talking about this on the Code Igniter forums.
http://codeigniter.com/forums/viewthread/165227/#846845
It looks like you set up your users DB as your main database in the config file, then you generate a config array for a new connection for a user based upon information in that users DB. So, I guess you'd need to at least store the DB name in the users database.
Not sure how well this works though, as I haven't had an occasion to try it out yet.
Sorry if that's not quite what you were looking for, but it should give you an idea of a Code Igniter approach.
Zend 框架。
http://framework.zend.com/manual/en/learning。多用户.intro.html
Zend Framework.
http://framework.zend.com/manual/en/learning.multiuser.intro.html