dongzhuang6247 2013-01-22 02:17
浏览 36
已采纳

codeigniter中的双重数据库[关闭]

I had a big portal in Codeigniter in which user can register and they can comment on each products, they can create their profiles, a forum ( custom made ) connected to this etc...

Also the company's main products also stored in the same DB.

The requirements is since the products tables are mpre important than users, now its some difficult for back up and all, I mean we have to split the database into two. ie one for users and their activities and other for main products.

I am bit confused to connect 2 dbs in a single codeigniter because we have to call/fetch data from both db's in a view / model

Any ideas ?

  • 写回答

1条回答 默认 最新

  • dtcyv3985 2013-01-22 02:22
    关注

    From here:

    http://ellislab.com/codeigniter/user-guide/general/models.html#loading


    Connecting to your Database

    When a model is loaded it does NOT connect automatically to your database. The following options for connecting are available to you:

    You can connect using the standard database methods described here, either from within your Controller class or your Model class. You can tell the model loading function to auto-connect by passing TRUE (boolean) via the third parameter, and connectivity settings, as defined in your database config file will be used:

    $this->load->model('Model_name', '', TRUE);
    

    You can manually pass database connectivity settings via the third parameter:

    $config['hostname'] = "localhost";
    $config['username'] = "myusername";
    $config['password'] = "mypassword";
    $config['database'] = "mydatabase";
    $config['dbdriver'] = "mysql";
    $config['dbprefix'] = "";
    $config['pconnect'] = FALSE;
    $config['db_debug'] = TRUE;
    
    $this->load->model('Model_name', '', $config);
    


    You can also setup this in config as db2 parameter and use in your controller as shortlink to the database settings.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条