Welcome Guest, Not a member yet? Register   Sign In
Grabbing secondary database info from default database.
#1

[eluser]slaytorson[/eluser]
Looking to get some opinions and suggestions.
I have 2 databases: main and secondary

The main database details are stored in the database.php file..

Now I need to connect to the secondary database however the connection info for the secondary database is coming from the main database.


I was thinking of this way:
User goes to login to site using main database while also getting secondary database connection info and store the secondary database info in maybe a session...


Ideas, Suggestions, Comments?

Thanks
#2

[eluser]rogierb[/eluser]
Easy, store the database info(host, username, password etc) in the database.
Get the database info.
Populate the config array.
Load the new database into a unique name with the config array.
Use it.

I do this with x databases, where depending on user 1->n databases are loaded.
My models use a connection string eg. $this->some_db, $this->another_db, instead off the useall $this->db

Code:
public function some_model_function($connection, $var1)
{
   $connection->where('id',$var);
   return $connection->get('table');
}
#3

[eluser]jdav3579[/eluser]
I have done this in the past too. But I think you need to set p_connect in both settings to false (I think! - it the opposite to the default!)
Otherwise you wont be able to connect to the two databases simultaneously.

John
#4

[eluser]slaytorson[/eluser]
What if I stored the database connection info in the session data?
#5

[eluser]slaytorson[/eluser]
[quote author="rogierb" date="1265031686"]Easy, store the database info(host, username, password etc) in the database.
Get the database info.
Populate the config array.
Load the new database into a unique name with the config array.
Use it.

I do this with x databases, where depending on user 1->n databases are loaded.
My models use a connection string eg. $this->some_db, $this->another_db, instead off the useall $this->db

Code:
public function some_model_function($connection, $var1)
{
   $connection->where('id',$var);
   return $connection->get('table');
}
[/quote]


So I would need to create a new custom module? I'm new to CI. However, learning pretty quickly. Could you give me more details.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB