I'm developing an application where each client will have their database. My scenario then will be: Client will login and through his ID apply the configuration of the bank for that client. Then, in addition to the default database, it will have a second where it will be related to that client, through its ID. In order for me to use the session ID I thought I would create a My_model
and put the second database there and make an extends on the models I'm going to use that second database. But I can not do it, follow the code as it is. Thank you for helping me.
<?php
class MY_Model extends CI_Model
{
protected $active_group;
protected $db2;
public function __construct() {
parent::__construct();
$this->connect();
}
public function __destruct() {
$this->db->close();
}
public function connect($active_group = 'default'){
$this->active_group = $active_group;
$db = $this->load->database($active_group, TRUE);
$this->db = $db;
$db['second'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'nomedobanco',
'dbdriver' => 'mysqli',
'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
);
//$db2 = $this->load->database('second', TRUE);
$this->db2 = $db;
}
}