在get_instance

时间:2018-08-07 11:13:30

标签: php mysql codeigniter

ff是我在配置文件上的数据库设置

$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';
...

我的自定义jcm_acl.php构造方法:

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');
 }

我运行了一些调试查询,以检查我的get_instance()在自定义库的__construct()方法中捕获的数据库。 ff是我的调试查询:

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

以下是调试查询的结果: vdebug($this->jcm_acl->ci->db->database);

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

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

请注意,get()方法所引用的数据库名称与第一个调试查询所显示的数据库名称不同。这是怎么回事。

仅当我访问同时加载第二个数据库的页面时,才会发生这种情况。在其他我没有加载第二个数据库的页面上,它工作得很好。

0 个答案:

没有答案