Is it possible for a PHP application built on top of codeigniter to simultaneously connect to a MySQL database and mongoDB?

I have a web application built into codeigniter and hosted with cloudcontrol . I am using a regular MySQL database for all my data, and now I want to use the mongodb database in addition to the MySQL database.

I want to use mongodb as a job queue to save messages between my workers and application servers. I got inspiration to do this from this tutorial: http://www.captaincodeman.com/2011/05/28/simple-service-bus-message-queue-mongodb/

  • Is this possible (using two different types of databases at the same time - with / without hacking codeigniter, I would suggest that it is)

  • Any tips for this?

---- EDIT ----

I have included this library in my CI project: https://github.com/alexbilbie/codeigniter-mongodb-library

And when I try to download it via: $this->load->library('mongo_db'); I come across this: enter image description here

I'm not sure how I can get mysql and mongodb to work together ...

---- EDIT ----

Do not pay attention to my previous question, I incorrectly configured the configuration file and confused the error ...

+5
source share
1 answer

Yes, it’s possible, out of the box.

You need to define two groups in your configuration: one for mysql and one for mongodb. In your application, you can upload to these databases by the name of the group.

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)

:

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

.

+6

All Articles