doupaxia2478 2011-04-02 16:57 采纳率: 100%
浏览 56

Codeigniter 2手动数据库连接

I have just been testing an upgrade to codeigniter 2 and have hit a snag. My site uses multiple databases, one being a 'system' database and one of several 'content' databases. Only two databases are loaded at once, the system and whichever content is necessary according to a value in the session.

Because of the use of session, I connect to relevant content database in the constructor of the controllers through a function in MY_Controller.

Somehow, since upgrading to codeigniter 2, the connection object to the content database doesn't make it to the model that would use it.

I.E. the variable of the connection is public'ed at the top of the controllers and model and MY_Controller and MY_Model but by the time it has reached MY_Model, it is no longer an object.

Any ideas what would reset the value of a variable as it is passed to the models in codeigniter 2 but not codeigniter 1.7.3?

  • 写回答

1条回答 默认 最新

  • douyang5943 2011-06-01 18:56
    关注

    Are both databases using same hostname, username, password?

    If yes then this is the same problem we just ran into: http://codeigniter.com/forums/viewthread/72240/P15/

    We solved it by creating to mysql users with different usernames, userA has access to dbA and userB has access to dbB.

    What is happening is when you have:

    1. $this->dbA = $this->load->database('dbA_config', true);
    2. $this->dbB = $this->load->database('dbB_config', true);

    When you run line #2 php looks to see if this connection is already open, problem is that php is only looking at the hostname, username, password so when you try to just change database PHP is actually updating dbA by reference.

    Hope that helps.

    -Noah

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?