Welcome Guest, Not a member yet? Register   Sign In
Session is not working in database.php file
#1

[eluser]web_developer[/eluser]
I have dynamic site database..

I have to load database according to site wise, I have DB settings in session variable.
But it doesn't working in database.php file.. Can anyone suggest? how can I get session variable in database.php file?


Code:
$active_group = 'mysite';
$db[$active_group]['hostname'] = (isset($_SESSION['mysite_db_host']))?$_SESSION['mysite_db_host']:'localhost';
$db[$active_group]['username'] = (isset($_SESSION['mysite_db_user']))?$_SESSION['mysite_db_user']:'abcd';
$db[$active_group]['password'] = (isset($_SESSION['mysite_db_pass']))?$_SESSION['mysite_db_pass']:'abcd';
$db[$active_group]['database'] = (isset($_SESSION['mysite_db_name']))?$_SESSION['mysite_db_name']:'';
$db[$active_group]['dbdriver'] = 'mysql';
$db[$active_group]['dbprefix'] = '';
$db[$active_group]['pconnect'] = TRUE;
$db[$active_group]['db_debug'] = TRUE;
$db[$active_group]['cache_on'] = FALSE;
$db[$active_group]['cachedir'] = '';
$db[$active_group]['char_set'] = 'utf8';
$db[$active_group]['dbcollat'] = 'utf8_general_ci';
$db[$active_group]['swap_pre'] = '';
$db[$active_group]['autoinit'] = TRUE;
$db[$active_group]['stricton'] = FALSE;
unset($active_group);
#2

[eluser]jjDeveloper[/eluser]
Codeigniters session class might be a better alternative as your db credentials are currently available to anyone on the server. Plus you would be able to use it in your model.
#3

[eluser]CroNiX[/eluser]
If you want to do that, why don't you just pass in the configuration array instead of using the database config file? You can do it manually.
Code:
$this->load->database($config);
#4

[eluser]Aken[/eluser]
Also consider using the ENVIRONMENT constant to set the appropriate environment, instead of directly using session variables.




Theme © iAndrew 2016 - Forum software by © MyBB