Possible for PHP app built on top of codeigniter to connect to a MySQL AND a mongoDB database at the same time? Possible for PHP app built on top of codeigniter to connect to a MySQL AND a mongoDB database at the same time? mongodb mongodb

Possible for PHP app built on top of codeigniter to connect to a MySQL AND a mongoDB database at the same time?


Yes this is possible, out of the box.

You need to define two groups in your config, one for mysql and one for mongodb. In your application you can then load in these databases by group name.

In your confugration.php:

$db['mysql']['hostname'] = "localhost";$db['mysql']['username'] = "root";$db['mysql']['password'] = "";$db['mysql']['dbdriver'] = "mysql";//... (full config omitted for brevity)$db['mongodb']['hostname'] = "localhost";$db['mongodb']['username'] = "root";$db['mongodb']['password'] = "";$db['mongodb']['dbdriver'] = "mongodb";//... (full config omitted for brevity)

And then you would load in your databases as follows:

$mysqlDB = $this->load->database('mysql', TRUE);$mongoDB = $this->load->database('mongodb', TRUE); 

Take a look at the user guide on how to connect to multiple databases and on how to specify configuration groups.