1

I loaded two different database in Codeigniter controllers _contruct in series. While I call the second database in action it works fine but first loaded db is referring second loaded db.

function __construct(){
  parent::__construct();  

 $this->liveDB = $this->load->database('liveDB', TRUE);
 $this->metricsDB = $this->load->database('metricsDB', TRUE);
}

My Action

$this->metricsDB->query("") // working good

$this->liveDB->query("") // referring database metricsDB

Note : If I change the order in __construct it works opposite

7
  • do you have your database set to autoload, if so what happens when you turn autoload database off? Commented Aug 14, 2013 at 7:54
  • @allen213: I tried removing 'database' from autoload. Still same Commented Aug 14, 2013 at 9:00
  • Have you put the right config entries for each in the database.php config file? Commented Aug 14, 2013 at 9:10
  • I'd imagine he has, as he states: " If I change the order in __construct it works opposite". Commented Aug 14, 2013 at 9:13
  • 1
    Have you tried any of the advice here : stackoverflow.com/questions/634291/… ? Commented Aug 14, 2013 at 9:13

2 Answers 2

1

This could be caused by persistent connect, set

$db['livDB']['pconnect'] = FALSE;
$db['metricsDB']['pconnect'] = FALSE;

in your database config see if that helps

Sign up to request clarification or add additional context in comments.

Comments

0

Have a look at CI User guide:

If you need to connect to more than one database simultaneously you can do so as follows:

$liveDB = $this->load->database('liveDB', TRUE);
$metricsDB = $this->load->database('metricsDB', TRUE);

Then you can use:

$metricsDB->query();
$metricsDB->result();

1 Comment

Make sure a database is not set to autoload -> application/config/autoload.php. As @allen213 mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.