[eluser]applepear[/eluser]
hi, there,
trust me... I know there are many discussion on this topic and tried to look at older posts on this. here is my problem.
i have two dbs, and here is how they are set up in database.php.
Code:
$active_group = 'userdb';
$active_record = TRUE;
$db['userdb']['hostname'] = 'localhost';
$db['userdb']['username'] = 'root';
$db['userdb']['password'] = '';
$db['userdb']['database'] = 'user';
$db['userdb']['dbdriver'] = 'mysql';
$db['userdb']['dbprefix'] = '';
$db['userdb']['pconnect'] = TRUE;
$db['userdb']['db_debug'] = TRUE;
$db['userdb']['cache_on'] = FALSE;
$db['userdb']['cachedir'] = '';
$db['userdb']['char_set'] = 'utf8';
$db['userdb']['dbcollat'] = 'utf8_general_ci';
$db['userdb']['swap_pre'] = '';
$db['userdb']['autoinit'] = TRUE;
$db['userdb']['stricton'] = FALSE;
$db['knowledgedb']['hostname'] = 'localhost';
$db['knowledgedb']['username'] = 'root';
$db['knowledgedb']['password'] = '';
$db['knowledgedb']['database'] = 'knowledge';
$db['knowledgedb']['dbdriver'] = 'mysql';
$db['knowledgedb']['dbprefix'] = '';
$db['knowledgedb']['pconnect'] = TRUE;
$db['knowledgedb']['db_debug'] = TRUE;
$db['knowledgedb']['cache_on'] = FALSE;
$db['knowledgedb']['cachedir'] = '';
$db['knowledgedb']['char_set'] = 'utf8';
$db['knowledgedb']['dbcollat'] = 'utf8_general_ci';
$db['knowledgedb']['swap_pre'] = '';
$db['knowledgedb']['autoinit'] = TRUE;
$db['knowledgedb']['stricton'] = FALSE;
this example involves a few model classes. user model class uses the userdb, and a few other classes uses the knowledgedb.
in user model class, DB is called by eg.
Code:
$this->db->get('user')
in eg. knowledge model class, i have
Code:
function __construct(){
$this->kdb = $this->load->database('knowledgedb', true);
}
function func1(){
....
$this->kdb->get('knowledge');
....
}
now in the controller, i have the following code:
Code:
function __construct(){
parent::__construct();
$this->load->model('user');
$this->loggedin = $this->user->is_loggedin();
$this->load->model(array('knowledge', 'subject'));
$this->param = $this->knowledge->func1();
}
and so far, everything works well. then in one of the functions, i have:
Code:
function comment($kid) {
$n = $this->knowledge->another_func();
$n->uid = $this->user->get_userid($param1);
}
the first call works fine, but the second call gives me a Database error as the following:
Quote:Error Number: 1146
Table 'knowledge.user' doesn't exist
SELECT * FROM (`user`) WHERE `username` = 'apple'
Filename: ....\system\database\DB_driver.php
Line Number: 330
I think I did exactly as said in the user guide... how come the call to user model class is with the wrong DB if this is called after the $this->load->model('knowledge'...)?
hope the story is told clearly... thanks to you all in advance.