EllisLab text mark
Advanced Search
     
two database
Posted: 13 November 2012 03:19 PM   [ Ignore ]
Joined: 2012-08-01
7 posts

Hello Dear I have another question, when trying to handle two connections to different databases, as I get to the right the model layer, for example:

database.php

$ active_group = ‘default’;
$ active_record = TRUE;

$ db [‘default’] [‘hostname’] = ‘localhost’;
$ db [‘default’] [‘username’] = ‘1 ‘;
$ db [‘default’] [‘password’] = ‘1 ‘;
$ db [‘default’] [‘database’] = ‘BD1’;
$ db [‘default’] [‘dbdriver’] = ‘mysql’;
$ db [‘default’] [‘dbprefix’] =’‘;
$ db [‘default’] [‘pconnect’] = FALSE;
$ db [‘default’] [‘db_debug’] = TRUE;
$ db [‘default’] [‘cache_on’] = FALSE;
$ db [‘default’] [‘cachedir’] =’‘;
$ db [‘default’] [‘char_set’] = ‘utf8’;
$ db [‘default’] [‘dbcollat​​’] = ‘utf8_general_ci’;
$ db [‘default’] [‘swap_pre’] =’‘;
$ db [‘default’] [‘autoinit’] = TRUE;
$ db [‘default’] [‘stricton’] = FALSE;

$ db [‘db2’] [‘hostname’] = ‘localhost’;
$ db [‘db2’] [‘username’] = ‘2 ‘;
$ db [‘db2’] [‘password’] = ‘2 ‘;
$ db [‘db2’] [‘database’] = ‘BD2’;
$ db [‘db2’] [‘dbdriver’] = ‘mysql’;
$ db [‘db2’] [‘dbprefix’] =’‘;
$ db [‘db2’] [‘pconnect’] = FALSE;
$ db [‘db2’] [‘db_debug’] = TRUE;
$ db [‘db2’] [‘cache_on’] = FALSE;
$ db [‘db2’] [‘cachedir’] =’‘;
$ db [‘db2’] [‘char_set’] = ‘utf8’;
$ db [‘db2’] [‘dbcollat​​’] = ‘utf8_general_ci’;
$ db [‘db2’] [‘swap_pre’] =’‘;
$ db [‘db2’] [‘autoinit’] = TRUE;
$ db [‘db2’] [‘stricton’] = FALSE;

model.php here where I refer to the DB2 connection in F1?

m_usuario class extends CI_Model
{
    / / put your code here
    function __ construct ()
    {
      parent :: __construct ();
     
    }
    function f1 ()
    {
      // connection to db2
      $ this-> db-> select (‘field1’);
      $ this-> db-> select (‘field2’);
      $ this-> db-> from (‘table1’);
      return $this->db->get()->row_array();
    }
}

thanks for all

 
Posted: 13 November 2012 04:03 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-01
22 posts

Hi Carlosmupe,

I think you are asking how you can communicate to one of the two databases. The official userguide explains how to do this: http://ellislab.com/codeigniter/user-guide/database/connecting.html.

Goodluck!

 
Posted: 14 November 2012 08:53 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-08-01
7 posts

thanks!!