Skip to content

Instantly share code, notes, and snippets.

@yangkun
Forked from jondavidjohn/MY_Controller.php
Last active December 22, 2015 08:48
Show Gist options
  • Save yangkun/6447009 to your computer and use it in GitHub Desktop.
Save yangkun/6447009 to your computer and use it in GitHub Desktop.
[codeigniter] using multiple database
<?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);
}
}
<?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');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment