【问题标题】:Codeigniter - Connecting to multiple database that are on different serverCodeigniter - 连接到不同服务器上的多个数据库
【发布时间】:2016-10-22 09:54:27
【问题描述】:

我想实现一个功能,我想根据用户选择的公司更改数据库。

例如:
User A访问我的站点时,他需要登录,登录后他可以搜索他的公司,直到此时我将用户连接到我的服务器数据库;在他搜索他的公司并按下完成按钮后,我必须连接到他的服务器并将我的服务器数据库动态更改为他的公司服务器数据库。 (这样做的原因是我的网络应用程序将被多家公司使用,因此公司会有不同的员工记录,所以我必须连接到他们服务器的数据库来获取他们的雇主记录)。

我真的很困惑如何实现这一点,我需要将哪些数据存储在我的数据库中以连接到不同的服务器数据库?
据我研究,我知道我需要存储dbname,dbusername,dbPassword

我还需要存储其他东西吗?我还需要存储主机名吗?你们谁能指导我如何实现这一目标?

【问题讨论】:

  • 欢迎来到 Stack Overflow,Tarzy,你的问题可能很好,但它是一大块没有代码 sn-ps 或图像的文本。
  • 我知道但很抱歉解释我的问题我可以使用一些文字..我要求一种方法来解决我的问题

标签: database codeigniter


【解决方案1】:
Are you creating individual database as per the company name of that employee, or are you using same database for all the employees?

If you are creating individual database for individual users, you store the company name in to your users information table and when ever you are login, you fetch the company name of that user and store it in to session

and while fetching the record you use the stored company name in to the session for connecting to the database as :

suppose you want to fetch the record from companymaster or some other table you can use like as :

 $companyName=$this->session->userdata('companyName');//stored company name in to the session
Now, use the table as

$this->db->from("$companyName"."Your Table Name");

Thanks.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2016-01-24
    • 2014-08-07
    • 2019-05-24
    相关资源
    最近更新 更多