How to connect multiple databases in CodeIgniter?

How to connect multiple databases in CodeIgniter?

Default Asked on June 7, 2018 in CODEIGNITER.
Add Comment
1 Answer(s)

Turn persistent connections off

$db['default']['pconnect'] = FALSE;

then added this library to /applications/config/autoload.php in the appropriate section:


/**
  * A simple class which handles loading multiple-databases in codeigniter
  */

 class DatabaseLoader {

         public function __construct() {
                 $this->load();
         }

         /**
          * Load the databases and ignore the old ordinary CI loader which only allows one
          */
         public function load() {
                 $CI =& get_instance();

                 $CI->db = $CI->load->database('default', TRUE);
                 $CI->db2 = $CI->load->database('db2', TRUE);
         }
Senior Developer Answered on July 2, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.