Welcome Guest, Not a member yet? Register   Sign In
Switch Database
#4

I think one of them could suite you when loading a model (from docs):
Use this in Controller.
PHP Code:
$db_config_file $this->config->load('database');
$config $this->config->item('default''database');

// Load model with DB1
$this->load->model('model_name'''$config);

// Load model with DB2
$config['database'] = 'DB2';
$this->load->model('model2_name'''$config);

// Load model with DB3
$config['database'] = 'DB3';
$this->load->model('model3_name'''$config); 

There're more advanced ways. In CI3, you have plenty of other options. But you will need to try coding it in first to see how things work.

You can also load database configuration using config library, then load them into models.

I can't guess what will suite you, but you need to see what's on the table and decide what you want to use and make your own approach. 

Various ways of loading configuration and database connections was especially made for you with dozens of ways to integrate your logic.

Controllers and Models are extensible, and could allow you to prepare connection before you load controllers or classes.
Reply


Messages In This Thread
Switch Database - by federcla - 04-13-2020, 10:44 AM
RE: Switch Database - by cyberstunts - 04-13-2020, 05:04 PM
RE: Switch Database - by federcla - 04-14-2020, 03:43 AM
RE: Switch Database - by cyberstunts - 04-14-2020, 05:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB