dynamic database connection |
[eluser]Unknown[/eluser]
Hi, I am newbie in CI, i come from .NET, and want to use CI for my new project as a web GUI. i have several databases, and i want to users able to manage their databases. users data stores in USERS_TABLE and database login info stores in SERVERS_TABLE. user must able to login and have access to related database (some controllers do logics ). in fact i want to generate dynamic database connection for user (based on related db info) in some controllers. how i can do this ? please suggest me some idea. tanks all.
[eluser]noideawhattotypehere[/eluser]
http://ellislab.com/codeigniter/user-gui...cting.html Where and how you will store new configs - its up to you, just dont use persistent connection set to true as this may cause unexpected results
[eluser]CroNiX[/eluser]
You don't have to store the config in a file which would defeat the point of a dynamic connection. Just create an array of the connection properties, like coming from your db for your specific user, and pass it to the load::database(). Code: $config['hostname'] = "localhost"; Now just use $db2 like you would $this->db and it will use the new connection instead of the default. Code: $db2->where('something', $id)->get('table')->result(); If you want it globally available, you should create a MY_Controller or library that is autoloaded, create a CI property to hold the connection, and load it there. |
Welcome Guest, Not a member yet? Register Sign In |