Welcome Guest, Not a member yet? Register   Sign In
Variable database name in config file (dbutil problems)
#1

[eluser]Unknown[/eluser]
What is the best way to achieve this? The thing i'm struggling with is that the database name (lets say 'userdb_197', for user #197), in the database config file can't be variable. There for, every time i need to access that database i manually need to make a database connection.

No problems till now, but when i want to use the dbutil class, i can't manually create a database connection, because it automatically uses the settings set in the database config file.

Is there anyway to make the 'database' element in the database config file variable?

Beneath is my config file. I have 2 databases. One variable depending on the user ('user'), and one a static one ('app'). So is there any way to make the database variable in the 'user' database, depending on the user.
Code:
$db['user']['hostname'] = "localhost";
$db['user']['username'] = "basje";
$db['user']['password'] = "*******";
$db['user']['database'] = "";
$db['user']['dbdriver'] = "mysql";
$db['user']['dbprefix'] = "";
$db['user']['pconnect'] = TRUE;
$db['user']['db_debug'] = TRUE;
$db['user']['cache_on'] = FALSE;
$db['user']['cachedir'] = "";
$db['user']['char_set'] = "utf8";
$db['user']['dbcollat'] = "utf8_general_ci";



$db['app']['hostname'] = "localhost";
$db['app']['username'] = "basje";
$db['app']['password'] = "*******";
$db['app']['database'] = "basis";
$db['app']['dbdriver'] = "mysql";
$db['app']['dbprefix'] = "";
$db['app']['pconnect'] = TRUE;
$db['app']['db_debug'] = TRUE;
$db['app']['cache_on'] = FALSE;
$db['app']['cachedir'] = "";
$db['app']['char_set'] = "utf8";
$db['app']['dbcollat'] = "utf8_general_ci";
#2

[eluser]WanWizard[/eluser]
dbutil uses the existing database connection, so that shouldn't be a problem.

To work around this, you can create the entire config array at runtime, or use
Code:
include(APPPATH.'config/database'.EXT);
$db['user']['database'] = $my_user_database;
$this->load->database($db['user']);
unset($db);
#3

[eluser]Unknown[/eluser]
*bump*
#4

[eluser]WanWizard[/eluser]
bump what?

I gave you a solution. If you don't like it, at least tell us why. Can't seem to find my crystall ball...




Theme © iAndrew 2016 - Forum software by © MyBB