jamierumbelow / codeigniter-base-model

⛔️DEPRECATED CodeIgniter base CRUD model to remove repetition and increase productivity
MIT License
1.05k stars 480 forks source link

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

Open sagark1510 opened 8 years ago

sagark1510 commented 8 years ago

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?

rscotten commented 8 years ago

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';