Welcome Guest, Not a member yet? Register   Sign In
Multiple databases
#1

[eluser]_Smilie_[/eluser]
Hi,
I work with many databases at once (5), and I need a better way of switching between them.
Currently I use this:
Code:
$this->db_forum = $this->load->database('forum', TRUE);
And it seems to work just fine. The problem is, that it for some reasons set this to the default database?
So.. I execute queries like this:
Code:
$this->db_forum
However my default DB is just:
Code:
$this->db
But when I load another database the $this-db seems to get changed, either way when calling it, it attempts to look in my forum database, if another controller used that as the last one.

Is there any way to globally force that $this-db should always be my default unless specifically declared otherwise?
#2

[eluser]Matalina[/eluser]
I don't ever use $this->db when using multiple databases.

Well I lie, I created a MY_Model to do that.

You can:
Code:
$this->db = $this->load->database('default', TRUE);
You have to do that in any model where you want to use it.
But I tend to do:

Code:
$this->db_main = $this->load->database('default', TRUE);

This is my multidatabase MY_Model construct where I use $this->db method

Code:
function __construct($database = 'default') {
    parent::__construct();
    $this->db = $this->load->database($database,TRUE);
  }




Theme © iAndrew 2016 - Forum software by © MyBB