Welcome Guest, Not a member yet? Register   Sign In
Problem with multiple databases
#1

[eluser]warrennz[/eluser]
Hey guys

Any ideas to help me solve this would be appreciated.

In my database configuration I have 2 databases.

One named 'default' and one named 'asimov'

The default database is set to 'default' and interacting with the database itself runs fine.

I have a model that looks like this
Code:
<?php
    class usage_model extends Model {

        function usage_model()
        {
            parent::Model();

             $this->asimov_db = $this->load->database('asimov', TRUE);
        }

..

When I load this model ( not actually even running queries with $this->asimov_db yet ), it appears to make ci use that as its default database.

So for example

I query the default database.
Code:
$this->db->get('users')->limit(20)->result();
Which is defiantly querying the table from default's database

then I load the model
Code:
$this->load->model('usage_model');

and finally if I try to run the same query again
Code:
$this->db->get('users')->limit(20)->result();
I get a mysql error saying that asimov.users doesn't exist
'Table 'asimov.users' doesn't exist'

So what am I doing wrong? I thought by passing true as the 2nd parameter, you return a new instance which doesn't effect the main ci instance?

Thanks in advance
#2

[eluser]warrennz[/eluser]
This is probably most likely the cause
http://ellislab.com/forums/viewthread/100374/

Any other suggestions appreciated




Theme © iAndrew 2016 - Forum software by © MyBB