Welcome Guest, Not a member yet? Register   Sign In
change database on the fly
#1

[eluser]Dariusz-Gdynia[/eluser]
Hi,
I have pretty huge web service with one database and I have to connect couple of users to another database, so:

99% of users should take data from db1
1% of users should take data from db2

I do not want to change every query I make because there are more than thousand of them.

In my head this should work like this:
User logs in, if ID is not on the list, nothing changes, if it is on the list, change db to db2.
Is there any chance to do that?

I tried placing "$this->load->database('db2');" in my model (which is loaded on every page) - it is connecting to db2 (because there is an error when there is no db2), but "$this->db" still connects to db1.

I also tried using session ($_SESSION AND $this->session) in config/database.php - but both variables are invisible there.
#2

[eluser]Mantero[/eluser]
maybe this post will help

http://ellislab.com/forums/viewthread/145901/#712942
#3

[eluser]Dariusz-Gdynia[/eluser]
It will not actually, it says that i need to use $this->db_forum->query("")...
and I want to use basic $this->db->query(""), but define (if it is possible define only once in one place, i.e. model) what database I'd like to use based on information in session (user id)
#4

[eluser]Unknown[/eluser]
Did you ever figure this out? I'm running into the same issue.
#5

[eluser]InsiteFX[/eluser]
CodeIgniter User Guide - Connecting to your Database
#6

[eluser]Unknown[/eluser]
here is a very simple solution to this:

$new_db = $this->load->database( $params, TRUE );
$this->db = $new_db




Theme © iAndrew 2016 - Forum software by © MyBB