I have codeigniter setup to connect 2 databases (default and site). I have to dynamically change the default database name and should use any new database using the default connection is there a way to do this?
The reason for this is that I want to set a cron script which runs commands on some databases, it is not possible to edit the application / config / database.php so it can be dynamically transformed. .
$ active_group = 'default'; $ Active_record = TRUE; $ Phppos_client_name = substr ($ _ server) ['HTTP_HOST'], 0, stropo ($ _ server ['HTTP_HOST'], '.')); $ Db ['site'] ['hostname'] = 'php-pos-db'; $ Db ['site'] ['username'] = 'ffount'; $ Db ['site'] ['password'] = 'password'; $ Db ['site'] ['database'] = 'flbvan_site'; $ Db ['site'] ['debibrier'] = 'mysical'; $ Db ['site'] ['debreffics'] = ''; $ Db ['site'] ['pconnect'] = false; $ Db ['site'] ['db_debug'] = false; $ Db ['site'] ['cache_on'] = falls; $ Db ['site'] ['cachered'] = ''; $ Db ['site'] ['char_set'] = 'utf8'; $ Db ['site'] ['dccol' '] =' utf 8_garg_g '; $ Db ['site'] ['swap_pre'] = ''; $ Db ['site'] ['autoinit'] = true; $ Db ['site'] ['streikton'] = false; $ Db ['default'] ['hostname'] = "php-pos-db"; $ Db ['default'] ['username'] = "pff"; $ Db ['default'] ['password'] = "password"; $ Db ['default'] ['database'] = "phppoint_ $ phppos_client_name"; $ Db ['default'] ['dbdriver'] = "MySQL"; $ Db ['default'] ['dbipfix'] = "phpps_"; $ Db ['default'] ['pconnect'] = Wrong; $ Db ['default'] ['db_debug'] = Wrong; $ Db ['default'] ['cache_on'] = falls; $ Db ['default'] ['cachered'] = ''; $ Db ['default'] ['char_set'] = 'UTF8'; $ Db ['default'] ['DBCOL'] = 'UTF 8_Incode_C'; $ Db ['default'] ['swap_pre'] = '; $ Db ['default'] ['autoinit'] = true; $ Db ['default'] ['stricon'] = falls; / * File End Database .php * / / * Location: ./application/config/database.php * /
The way you want me to think that it is not possible you can do it in an alternate way
1. Do not load the database on your autoload config.
2. Manually copy your database from $ this-> Load-> Using the database ('site'),
$ this-> Load-> Database ('default')