Question about multiple databases - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Question about multiple databases (/showthread.php?tid=12276) |
Question about multiple databases - El Forum - 10-13-2008 [eluser]St0neyx[/eluser] hi all i'm building a project where i'm using 2 databases, both are on the same server as the website. now i read a lot of topics and the userguide, and what i find is this. Code: $DB1 = $this->load->darabase('dbname 1', true); now i tryd this, but it isn't working as i hoped.. Im using a lot of DHTML and ajax in my project, wich means that i use a lot of calls to functions. now when i call a function that needs to gether data from both databases i did this: Code: $DB1 = $this->load->darabase('dbname 1', true); This will not work because when the first query is send, it usses the second db connection. Kinda wierd because i put them in different variables. To make it work i have to do this (in every function) Code: $DB1 = $this->load->darabase('dbname 1', true); So my solution is, i made a model (db_model): Code: function query($query, $db) Call from function: Code: $query1 = "SELECT * FROM bla"; This will work, but im not sure if this is the way to fix it. Can i get some feedback on this?? Kind regards Question about multiple databases - El Forum - 10-13-2008 [eluser]xwero[/eluser] I think you have to set the pconnect setting to false if you want to use 2 databases at the same time. Question about multiple databases - El Forum - 10-13-2008 [eluser]St0neyx[/eluser] [quote author="xwero" date="1223910130"]I think you have to set the pconnect setting to false if you want to use 2 databases at the same time.[/quote] I saw that pconnect is one of the major causes for this, but then again if i set it to false i still have to make all the steps for a query 1. select the right db 2. make query 3. send query 4. close db 5. do something with result Can't i just define both dbs and then set pconnect to false so the only steps are 1. make query 2. send query 3. do something with result i cant put them in the construct because that one is not called. |