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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧