sunshine
sunshine

Reputation: 381

writing to database.php and creating file in codeigniter

I am trying to add the config statements using code into config->database.php, how to add statements to the config file and create a new connection group each time a tenant is registered. How to write to a file in codeigniter ?

I want to add the below statements dynamically to database.php once a tenant is created:

$db['uup']['hostname'] = 'localhost';
$db['uup']['username'] = 'root';
$db['uup']['password'] = '';
$db['uup']['database'] = 'uup';
$db['uup']['dbdriver'] = 'mysql';
$db['uup']['dbprefix'] = '';
$db['uup']['pconnect'] = TRUE;
$db['uup']['db_debug'] = TRUE;
$db['uup']['cache_on'] = FALSE;
$db['uup']['cachedir'] = '';
$db['uup']['char_set'] = 'utf8';
$db['uup']['dbcollat'] = 'utf8_general_ci';
$db['uup']['swap_pre'] = '';
$db['uup']['autoinit'] = TRUE;
$db['uup']['stricton'] = FALSE;

Upvotes: 0

Views: 210

Answers (1)

B.S.B.
B.S.B.

Reputation: 350

You can use below function to update configuration :

$this->config->set_item('config_array_index','value_to_set');

But, Setting a config item only applies to the current session - it does not overwrite your actually codeigniter files.

If you want to permanetly take a site offline, your'll need some sort of persistant storage, such as a value in a database that is checked/updated as needed

Doc: http://codeigniter.com/user_guide/libraries/config.html

Upvotes: 3

Related Questions