codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

How can I make parallel connection to two DBs on a Model?

Open sagark1510 opened this issue 10 years ago • 1 comments
trafficstars

Hi as per the documnetation $_db_group = 'group_name'; will make this->_db to point on defined db but how can I make a persistant connection to both db and query both of them at a time?

sagark1510 avatar Oct 07 '15 12:10 sagark1510

The current version of MY_Model is missing this capability despite the documentation claiming it exists.

To fix, add to the VARIABLES section of MY_Model (before the constructor)

protected $_db_group;

Then in the constructor replace

$this->_database = $this->db;

with

$this->_database = empty($this->_db_group) ? $this->db : $this->load->database($this->_db_group, TRUE);

And then initialize$_db_groupin your model that extends MY_Model:

public $_db_group = 'your_database_name';

rscotten avatar Dec 26 '15 00:12 rscotten