![]() |
Grabbing secondary database info from default database. - 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: Grabbing secondary database info from default database. (/showthread.php?tid=27085) |
Grabbing secondary database info from default database. - El Forum - 02-01-2010 [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 Grabbing secondary database info from default database. - El Forum - 02-01-2010 [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) Grabbing secondary database info from default database. - El Forum - 02-01-2010 [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 Grabbing secondary database info from default database. - El Forum - 02-01-2010 [eluser]slaytorson[/eluser] What if I stored the database connection info in the session data? Grabbing secondary database info from default database. - El Forum - 02-01-2010 [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) 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! |