Reputation: 1251
I'm working on 20 websites and each one has his own database, but they have the same structure of database.
The problem is that I have to login to the different back-end to do some work on each one.
So, I decided to write single CI back-end for all of the websites.
For that, I created a database with two tables (user
, websites
)
The user
table is for the login action.
The websites
table list all websites and the associated database.
What I would like to do is, in any view of my backend application, be able to select the database (or website), so that the current view can be reloaded with data from the selected database to perform some work on it and then submit it.
I'm using CI V1.7.2
Upvotes: 0
Views: 60
Reputation: 2180
This seems very plausible. However, note that once you change the database adapter, database session storage will not work as you expect since it's stored in the first database that you've mentioned.
So after when you verified the user and grabbed the database's DSN (database source name), you can change the database adapter when executing your queries by doing:
$this->database->load('dbdriver://username:password@hostname/database');
Note that dbdriver
is the type of database you are using, refer to the config file for the types. You can also take a look at the documentation for more information.
If you want database session storage to work, you may want to create a new database adapter, the method is similar from above, but there's one more parameter.
$new_db = $this->database->load($dsn, TRUE);
However, this method would most likely require some refactoring in your code since you're used to performing queries like $this->database->query();
and you'll need to change it to $new_db->query()
.
Upvotes: 1