Welcome Guest, Not a member yet? Register   Sign In
Having problems with data persistency - or how to keep a DB connection alive?
#1

[eluser]duartix[/eluser]
Cheers.

Here's my problem. I've just discovered that PHP (and a lot of web protocols) are stateless and that all variables are lost between requests... Sad

This is posing me with a big problem. I have the need to keep the login information in order to re-establish the database connection between requests. I've stored that information on user session variables through my home controller, like this:

Code:
$this->session->set_userdata('username', $_POST['username']);
$this->session->set_userdata('password', $_POST['password']);
$this->session->set_userdata('hostname', $_POST['hostname']);

and then I set them on database.php like this:

Code:
$CI =& get_instance();
$db['oracle']['username'] = $CI->session->userdata('username');
$db['oracle']['password'] = $CI->session->userdata('password');
$db['oracle']['hostname'] = $CI->session->userdata('connectString')

so that when the db connection is loaded, those values are read.

I've successfully implemented a login mechanism this way, but now the problem is that as soon as I load the first model to fetch data from the database, I don't have that session data anymore and when CI goes through database.php it has no access to those parameters anymore...

To add insult to injury, the database where the users connect to, are dynamic, so I will need constant access to username/password/SID (they are all Oracle) to load the database in the models.

Any suggestions on how to approach this problem?

Thank you.


Messages In This Thread
Having problems with data persistency - or how to keep a DB connection alive? - by El Forum - 09-24-2013, 08:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB