更改数据库连接数组codeigniter

时间:2016-11-28 06:10:48

标签: php sql-server codeigniter

我是CI的新人, 有人可以帮忙吗? 我有2个数据库连接:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '10.1.0.166',
    'username' => 'sa',
    'password' => 'Sprite12345',
    'database' => 'HRD',
    'dbdriver' => 'sqlsrv',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

$db['credit'] = array(
    'dsn'   => '',
    'hostname' => '10.1.0.166',
    'username' => 'sa',
    'password' => 'Sprite12345',
    'database' => 'BHAKTI',
    'dbdriver' => 'sqlsrv',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

现在,我试图更改$ db [' credit']的数据库值。 像这样的东西:

$db2 = $this->load->database('credit', TRUE);
$db2->database = 'BIT';
echo $db2->database;

$db2 = $this->load->database('credit', TRUE);
$db2->select('*');
$db2->from('tblconfig');
$query = $db2->get()->result();
print_r($query);

但查询结果仍然从BHAKTI获取tblconfig而不是BIT。 如何更改config / database.php中的数据库值?

提前致谢。

0 个答案:

没有答案