Welcome Guest, Not a member yet? Register   Sign In
Hybrid Session When Using Multiple Databases for Sharding
#1

[eluser]Unknown[/eluser]
We are currently trying to implement sharding for our CI app but have run into an issue we can't seem to figure out.

We have a directory database (DB1) that has all our users, passwords, and the database groups which each user is located.
We use the database session feature of CI to store our session variables.

This is how we would like to implement our sharding.

1. The user enters their credentials
2. Database 1 gives the location of the users database.
3. We then connect to Database 2 using the group name given from Database 1
4. We then insert the session and all transactions into Database 2.

Currently, the system connects to our Database 1 using:
$this->load->database('DB1');

When we query and get a result from DB1 where the users database is, we connect to it using:
$this->load->database('DB2');

We then try and set session data to DB2 stating the user is logged in using:
$this->session->set_userdata($data);

But the data is never entered into DB2 (the table is not inserted and is left empty).

Are we using the correct process to switch the session data entry from DB1 to be read from DB2?

Thanks in advance for any replies.
#2

[eluser]WanWizard[/eluser]
The session library requires $this->db to be available. If not, it creates it using the default database configuration.

Either make sure that you have a $this->db available that connects to DB2, or make sure DB2 is the default database connection in your config/database.php.
#3

[eluser]Unknown[/eluser]
How do you switch around the database to be associated with $this->db and $this->session?

I would assume the following would save the session variables 'value' = '1' in DB1 and 'value' = '2' in DB2,
but instead it just manipulates all the data in DB1

$this->load->database('DB1');
$db1_values = array('value'=>'1');
$this->session->set_userdata($db1_values);

$this->load->database('DB2');
$db2_values = array('value'=>'2');
$this->session->set_userdata($db2_values);

Am I implementing it correctly?




Theme © iAndrew 2016 - Forum software by © MyBB