codeigniter 单应用程序多数据库
我将把我的代码库转移到新的 2.0 框架,只是对以下几点有几个问题
我的网址如下
- example.in/city1
- example.in/city1/admin
- example.in/city2
- example.in/city2 /admin
我想知道根据网址中的城市切换数据库的最佳方法是什么? 。
在我的 webroot 中,我将拥有像 city1、city2 这样的目录,每个目录都包含一个指向单个代码库的 index.php 文件。
现在我只需要一种根据输入的网址切换数据库的方法。
问候, 谢尔顿
I will be shifting my code base to the new 2.0 framework and just had a few questions on the following points
My urls will be as follows
- example.in/city1
- example.in/city1/admin
- example.in/city2
- example.in/city2/admin
I would like to know what would be the best way to switch the database based on the city in the url? .
In my webroot i will have directories like city1, city2 each containing an index.php file which points to the single code base.
Now i only need a way to switch the database based on the url entered.
Regards,
Sheldon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我完全同意@poelinca 和@Ross,你绝对应该考虑重新考虑你的设计。
然而,对于参考问题,这个主题已经在 CodeIgniter 论坛中这里很好地涵盖了,
基本上你只是每个连接配置另一组
$db
项,然后通过 CodeIgniter 框架根据这些配置参数请求连接,方法是提供新的$db
作为$db
的参数code>DB 类构造函数。I completely agree with @poelinca and @Ross, you should definitely consider rethinking your design.
however for reference issues this topic was already covered in the CodeIgniter forums pretty well over here
Basically you just configure another set of
$db
items per connection and then request the connection based on those configuration parameters by the CodeIgniter framework, by providing the new$db
as a parameter for theDB
class constructor.