Welcome Guest, Not a member yet? Register   Sign In
How can I manage mutiple databases?
#2

Yes, the documentation doesn't explain the entire process. It does tell you how to set up the two groups in config/database.php. You know that part. Now what you do is this.

In your model file, make it look like this
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


Class 
Some_model extends CI_Model {
  
    
public $db1;
 
   public $db2;

 
   public function __construct()
 
   {
 
       parent::__construct();
 
       $this->db1 $this->load->database('database_1'TRUE);
 
       $this->db2 $this->load->database('database_2'TRUE);
 
     

Then, in your model functions, you do this
PHP Code:
public function get_records_1()
{
 
   return $this->db1->query('SELECT * FROM table_name;')
}

public function 
get_records_2()
{
 
   return $this->db2->query('SELECT * FROM table_name;')


In your controller, you don't have to do anything special. Just like normal.
PHP Code:
$records_1 $this->some_model->get_records_1();
$records_2 $this->some_model->get_records_2(); 
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply


Messages In This Thread
RE: How can I manage mutiple databases? - by RobertSF - 02-19-2015, 02:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB