I have a web application built in codeigniter and hosted with cloudcontrol. I use a normal MySQL database for all of my data persistance, and now I want to use a mongodb database in addition to the MySQL database.
I want to use mongodb as a job queue to persist messages between my workers and my application servers. I've gotten the 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 simultaniously -- with/without hacking codeigniter, I would assume it is)
Any tips for accomplishing this?
---- EDIT ----
I've included this library in my CI project: https://github.com/alexbilbie/codeigniter-mongodb-library
And when I attempt to load it via: $this->load->library('mongo_db');
I run into this:
I'm not sure how I can get mysql and mongodb working together...
---- EDIT ----
Nevermind my above question, I improperly set up the config file and confused the error...
it is very easy to configure multiple databases in CodeIgniter app. you can simply add database query, join etc with multiple databases. As we know well, in today we may need to add multiple databases on our application. all then framework provides multiple database connections.
To connect our CodeIgniter application to MongoDB, we'll need to install the MongoDB PHP Driver. The driver consists of two components—the extension and the library.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With