Welcome Guest, Not a member yet? Register   Sign In
DB switch after login
#1

[eluser]Artemis Mendrinos[/eluser]
I have one mysql DB with just one table "accounts".

I need right after the user login to stop using the default login details from the database.php on the config folder but use the new ones, the db name, username and pass which are stored in the account table. In order when the user is logged in to interact only with its own database (I will maintain similar db scheme between all users).

Till now I have tried to add to the construction of my custom controller:

Code:
if($this->session->userdata('logged_in')) {

$dsn = 'mysql://db_user:db_pass!@localhost/db_name?char_set=utf8&dbcollat=utf8_general_ci&cache_on=false';

            $this->load->database($dsn);
            
            $this->db->query('use ' . 'dbname' );

But it seems when I use $this->db-> it still works with the default credentials.. and not the credentials defined on the $dsn.

Is any other way to achieve what I need?
#2

[eluser]David Johansson[/eluser]
If your database is autoloading the $this->db varibale is already set. Maybe if you try create a diferent connection like
Code:
$db2 = $this->load->database($dsn, TRUE);
and then interact with it by
Code:
$db2->query('use ' . 'dbname' );




Theme © iAndrew 2016 - Forum software by © MyBB