Welcome Guest, Not a member yet? Register   Sign In
How to reuse an established DB connection in an another controller ?
#6

[eluser]TheFuzzy0ne[/eluser]
OK, so your user will need to be logged in, and will therefore have cookies enabled. You could store the username and password in the session, and create a custom controller that will load the database. Something like this:

./system/application/libraries/MY_Controller.php
Code:
class MY_Controller extends Controller {
    
    function MY_Controller()
    {
        parent::Controller();

        if ($db_info = this->session->userdata('db_data');)
        {
            // The users information can be stored in an array in the session.
            $dsn = 'oci8://' . $db_info['username'] . ':' . $db_info['password'] . '@local_db';        
            $this->load->database($dsn);
        }
    }
}

// End of file: MY_Controller.php
// Location: ./system/application/libraries/MY_Controller.php
The above code is untested.

Just ensure any controllers that require your user to be logged in extend the MY_Controller class.

You might need some more logic in there to handle situations where the information is incorrect before the database is called upon by any of your controller methods, but hopefully this will help you.


Messages In This Thread
How to reuse an established DB connection in an another controller ? - by El Forum - 03-02-2009, 09:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB