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?
    – allen213
    Aug 14, 2013 at 7:54
  • @allen213: I tried removing 'database' from autoload. Still same
    – Gowri
    Aug 14, 2013 at 9:00
  • Have you put the right config entries for each in the database.php config file?
    – Nishant
    Aug 14, 2013 at 9:10
  • I'd imagine he has, as he states: " If I change the order in __construct it works opposite".
    – allen213
    Aug 14, 2013 at 9:13
  • 1
    Have you tried any of the advice here : stackoverflow.com/questions/634291/… ?
    – allen213
    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

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
  • Make sure a database is not set to autoload -> application/config/autoload.php. As @allen213 mentioned.
    – Boris
    Aug 14, 2013 at 8:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.