0

can i connection with multiple database main connections is from database.php

but the another one in from the model and i want to switch between it

like this

        $config['remote']['hostname'] = 'localhost';
        $config['remote']['username'] = 'root';
        $config['remote']['password'] = '';
        $config['remote']['database'] = 'countries';
        $config['remote']['dbdriver'] = 'mysql';
        $config['remote']['dbprefix'] = '';
        $config['remote']['pconnect'] = TRUE;
        $config['remote']['db_debug'] = TRUE;
        $config['remote']['cache_on'] = FALSE;
        $config['remote']['cachedir'] = '';
        $config['remote']['char_set'] = 'utf8';
        $config['remote']['dbcollat'] = 'utf8_general_ci';
        $config['remote']['swap_pre'] = '';
        $config['remote']['autoinit'] = TRUE;
        $config['remote']['stricton'] = FALSE;

        $this->load->database($config);

        $this->load->database('remote', TRUE);
hakre
  • 178,314
  • 47
  • 389
  • 754
dev.bashar
  • 181
  • 1
  • 2
  • 14

1 Answers1

1

The basic syntax to use multiple database is following.

$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

The only difference Here is that you have to use the returned database object.

See notes on code igniter user guide on Connecting to Multiple Databases section

Note: Change the words "group_one" and "group_two" to the specific group names you are connecting to (or you can pass the connection values as indicated above).

By setting the second parameter to TRUE (boolean) the function will return the database object.

Community
  • 1
  • 1
Shiplu Mokaddim
  • 52,462
  • 12
  • 127
  • 180