![]() |
Conencting to multiple databases at same time, without knowing second database details to start with - 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: Conencting to multiple databases at same time, without knowing second database details to start with (/showthread.php?tid=48838) |
Conencting to multiple databases at same time, without knowing second database details to start with - El Forum - 01-30-2012 [eluser]DavidHopkins[/eluser] Hello all, im new to codeigniter and am really enjoying it. However i have a slight issue with database connections, well two databases connections to be honest. My application i am trying to build has a default database that has all the users details etc. THis is used to log in and carry out other basic funcitons. I have set this database up using the config inside database.php and can use it by just calling $this->db-> My problem comes however when i try to add a second database, which is unique to each person who logs in so i dont know their details until they have logged in. I wish to set this database up in such a way i can access it like $this->db2-> Can anyone please help me with this ? SOme example code would be great ! THanks David Hopkins Conencting to multiple databases at same time, without knowing second database details to start with - El Forum - 01-30-2012 [eluser]Kamarg[/eluser] Code: // Get users personal database info from whatever location it is stored in Of course, I can't help but think that any application design that gives every single user two connections to the database server is probably not going to scale all that well. If possible you may want to rethink your architecture. Edit: Guess escaping quotes doesn't fix the color scheme. Conencting to multiple databases at same time, without knowing second database details to start with - El Forum - 01-30-2012 [eluser]DavidHopkins[/eluser] Hey, thanks for the reply, in relation to your statement about not scaling all that well, could you please explain a little bit ? im unsure how it will effect it? Thanks Conencting to multiple databases at same time, without knowing second database details to start with - El Forum - 01-30-2012 [eluser]cideveloper[/eluser] Code: $query = $this->db->query("select user_db, user_username, user_password from master_table where user_id='user_id'"); All user stuff will now use the last line. Obviously this is a very simplified version as you probably should be using models for database actions |