![]() |
SOLVED: Dynamic database connections inheritance - 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: SOLVED: Dynamic database connections inheritance (/showthread.php?tid=12969) |
SOLVED: Dynamic database connections inheritance - El Forum - 11-06-2008 [eluser]rogierb[/eluser] This one got me puzzled, hopefully someone can offer me a solution;-) I have a number of database servers I have to connect to, for every company there can be a server or several companies reside on the same server I do not now how many servers I have to connect to AND I might have to connect to the same server a couple of times depending on a lot of variables. So here is what I did: On the master server I stored all possible connections with a connection_name and a company_id Together they form a unique connection name eg "ADCB123" where connection_name is "ADCB" and the company_id is "123". Depending on page-needs I create a variable variable "ADCB123" in which I load the connection. If the variable variable already exists I use the connection rather then loadig it again. Now here the problem, if I check id the connection exists in the controller, it works like a charm. When it doen't exist, it creates it, otherwise is doesn't do anything. But when I try to do the same in a model, it always creates a new connection. How can I let the model inherit already created connections from the controller? Is this even possible? If I call the same function from a model twice in a row, it creates the conenctions twice. How can I prevent this? Hope this makes any sence;-) Thanx for taking the time, Rogier SOLVED: Dynamic database connections inheritance - El Forum - 11-07-2008 [eluser]rogierb[/eluser] A new morning and a good night of comatose sleep brought the solution. Instead of using a variable variable like Code: $$connection Code: ${$this->connection} Code: $this->$connection Seems so simple and more CI-isch on this bright and early morning... ![]() |