Created
July 8, 2011 19:56
-
-
Save jondavidjohn/1072683 to your computer and use it in GitHub Desktop.
Loading Multiple Databases with Codeigniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** | |
* filepath: application/controllers/example.php | |
*/ | |
//Extend the Base Controller | |
class Example extends DB_Controller { | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
function index() | |
} | |
//Then use them in any controller like this | |
$data['billing'] = $this->inventory_db->get('stuff'); | |
$data['inventory'] = $this->billing_db->get('stuff'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** | |
* filepath: application/core/MY_Controller.php | |
*/ | |
//setup your base controller | |
class DB_Controller extends CI_Controller { | |
//declare them globally in your controller | |
protected $billing_db; | |
protected $inventory_db; | |
function __construct() | |
{ | |
parent::__construct(); | |
//Load them in the constructor | |
$this->billing_db = $this->load->database('billing', TRUE); | |
$this->inventory_db = $this->load->database('inventory', TRUE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment