![]() |
Connecting to two databases simultaneously - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Connecting to two databases simultaneously (/showthread.php?tid=23724) |
Connecting to two databases simultaneously - El Forum - 10-20-2009 [eluser]jdav3579[/eluser] Hi, I have checked the docs for this answer, but can't seem to get this to work. I have the folowing code, but in the getPage function it always attempts to use $db2 where it should be trying to use $db1. Any help kindly appreciated! John class content extends Model{ var $db1; var $db2; function content(){ parent::Model(); $this->db1=$this->load->database('default', TRUE); $this->db2=$this->load->database('group2', TRUE); } function getPage($parent, $heading){ $query=$this->engine->query("SELECT * FROM content "); return $query->row_array(); } } Connecting to two databases simultaneously - El Forum - 10-20-2009 [eluser]pistolPete[/eluser] Please use [ code ] tags! What exactly is $this->engine ? Did you try Code: $query = $this->db1->query('SELECT * FROM content'); Connecting to two databases simultaneously - El Forum - 10-20-2009 [eluser]jdav3579[/eluser] Hi thanks for the reply. sorry yes. The engine version was my original code. I thought I had removed all references to it when I posted! I have tried the code you posted but to no avail! It still tries to use the db set up in db2 though... So very wierd.. is there any thing I need to do in the configuration to indicate that I am using 2 dbs? Cheers john Connecting to two databases simultaneously - El Forum - 10-20-2009 [eluser]pistolPete[/eluser] Do you load the database automatically? Are you sure your database.php contains two different sets of database settings? Do you use persistent connections? Try: Code: $db['default']['pconnect'] = FALSE; Connecting to two databases simultaneously - El Forum - 10-20-2009 [eluser]jdav3579[/eluser] Originally I did load 1 automatically, but then figured this was possibly the problem. so loaded them manually. In your example is default one of the parameters you pass when loading the database? I am just checking, to make sure this isnt the problem. I cant try your code till tomorrow now as the problem is in work, but I will have a look then and post a reply then. But thanks for your efforts! John Connecting to two databases simultaneously - El Forum - 10-21-2009 [eluser]CroNiX[/eluser] pistolPete is referring to the database config file. Connecting to two databases simultaneously - El Forum - 10-21-2009 [eluser]jdav3579[/eluser] Cheers in my database config I have Code: $active_group=""; Connecting to two databases simultaneously - El Forum - 10-21-2009 [eluser]jdav3579[/eluser] Hi, Changing the pconnect seems to have worked. Thanks very much for your help! |