Welcome Guest, Not a member yet? Register   Sign In
Separate DB connection for single model
#1

I need a separate DB connection for single model. At the beggining i thought that it can be solved by loading model via:
Code:
$this->CI->load->model('some_model','','db_configuration_name');

but it is switching db connection for whole application, so any db call after that (also in other models loaded later) uses this connection.

Making change in constructor of model like this:
Code:
$this->db2 = $this->load->database('db_configuration_name',TRUE);
and using then only $this->db2 in this model id the only solution ?
Reply
#2

First you need to set both db connections in your config file
$db['default'] = array(
and
$db['stores'] = array(

in the model you can then create a Db connection like this

$default_db = this->load->database();

or

$stores_db = $this->load->database('stores', true);

then use the object to access the two databases

$stores_db->select('reference, company, email')
On the package it said needs Windows 7 or better. So I installed Linux.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB