0

I'm new in CI, can someone help ? I have 2 database connections :

$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
);

And now, I'm trying to change the database value of $db['credit']. something like this :

$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);

But the query result still take the tblconfig from BHAKTI not from BIT. How can I change the database value in the config/database.php ?

Thanks in advance.

Tale Words
  • 55
  • 8
user3859812
  • 11
  • 1
  • 6
  • Possible duplicate of [Change the database name on the fly in CodeIgniter 3](http://stackoverflow.com/questions/30899449/change-the-database-name-on-the-fly-in-codeigniter-3) – Rav Nov 28 '16 at 06:19
  • http://stackoverflow.com/questions/11622872/how-to-connect-with-user-specified-database-in-codeigniter – Veerendra Nov 28 '16 at 06:19
  • Can't you do it using session? – Akshay Nov 28 '16 at 06:23

0 Answers0