multiple databases...is there a way to unload?

#1
[eluser]sublight[/eluser]
Okay, I've tried this two ways, the first way:

//load DB1
$this->load->database('secret');
$query = $this->db->query('SELECT * FROM user WHERE id = '.$id);

//insert DB2
$this->load->database('notsecret');
$sql = "INSERT INTO comments blah blah blah";
$this->db->query($sql);
will always try to insert the "comments" db into secret instead of notsecret...

But if I do as the manual says when setting up two dbs:

//load two databases
$secretDB = $this->load->database('secret', TRUE);
$notsecretDB = $this->load->database('notsecret', TRUE);

$query = $secretDB->query('SELECT * FROM user WHERE id = '.$id);
$sql = "INSERT INTO comments blah blah blah";
$notsecretDB->query($sql);

It tries to query the user from notsecret instead of secret. Notsecret is the default in the database config.

Is there a way to unload the db in between or am I missing a command?

Thanks for your time! I appreciate your help.

#2
[eluser]sublight[/eluser]
I've seen two other posts with this same problem and neither of them had a reply. Is this a bug?

#3
[eluser]sublight[/eluser]
Okay, so I found this other message, which is a little more helpful and still vague so I'm going to explain how I've found that it works through pure trial and error. It ONLY works this way for me for whatever reason. Loading the databases together always defaults to the last loaded database, essentially "unloading" the previous database making the multiple database accessibility useless.

Code:
//load first database
$this->secretDB = $this->load->database(’secret’, TRUE);

$query = $secretDB->query(’SELECT * FROM user WHERE id = ‘.$id);

//load second database
$this->notsecretDB = $this->load->database(’notsecret’, TRUE);

$sql = “INSERT INTO comments (comment_column) VALUES (".$this->notsecretDB->escape($comment_column).")”;

$this->notsecretDB->query($sql);

I found this message
http://ellislab.com/forums/viewthread/87824/
which clued me into the
Code:
$this->actualdbvar = $this->load->database(’dbnameindatabaseconfig’, TRUE);
which is NOT in the documentation. I also found out that you must use
Code:
$this->actualdbvar->escape
and not
Code:
$this->db->escape
as shown on the documentation here:
http://ellislab.com/codeigniter/user-gui...eries.html

If you use the suggested $this->db->escape it will give you a blank page with no error.

As far as I can tell, there is no unloading mechanism, just loading in sequence, and no "preloading" for later use which is a major pain.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.