duandai7601 2018-08-07 11:13
浏览 43

Codeigniter上的多个数据库在get_instance期间在自定义库上无法正常工作

The ff is my database setup on my config file

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '#########';
$db['default']['database'] = 'fault_analytics';
$db['default']['dbdriver'] = 'mysql';
...

$db['SiteDB']['hostname'] = 'localhost';
$db['SiteDB']['username'] = 'root';
$db['SiteDB']['password'] = '#########';
$db['SiteDB']['database'] = 'smartSiteDB';
$db['SiteDB']['dbdriver'] = 'mysql';
...

my custom jcm_acl.php construct method:

function __construct() {
    $this->ci =& get_instance();
    $this->ci->load->helper('url');
    $this->ci->load->library('session');
    $this->ci->load->helper('string');
    $this->ci->load->config('jcm_acl');
    $this->ci->load->model('jcm_acl_model', 'acl');

    $this->tables = $this->ci->config->item('tables');
    $this->default_error_page = $this->ci->config->item('default_error_page');
    $this->use_default_error_page = $this->ci->config->item('use_default_error_page');
 }

I ran some debug queries to check the database captured by my get_instance() on my custom library's __construct() method. The ff are my debug queries:

vdebug($this->jcm_acl->ci->db->database);
vdebug($this->jcm_acl->ci->db->list_tables());
vdebug($this->jcm_acl->ci->db->get('users'));
die();

Below are the results of the debug queries: vdebug($this->jcm_acl->ci->db->database);

vdebug($this->jcm_acl->ci->db->list_tables());

$this->jcm_acl->ci->db->get('users')

Notice the database name being referred to by the get() method, its not the same with the database name as shown by the first debug query. How is this happening.

This only happens when I access the page where I also load the second database. On other pages where I do not load the second database, It works perfectly fine.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号