Welcome Guest, Not a member yet? Register   Sign In
SOLVED: Dynamic database connections inheritance
#1

[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
#2

[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
or
Code:
${$this->connection}
I just used
Code:
$this->$connection
where $connection is a concatenated string.

Seems so simple and more CI-isch on this bright and early morning...

Tongue




Theme © iAndrew 2016 - Forum software by © MyBB