可能的PHP应用程序建立在codeigniter之上连接到MySQL和一个mongoDB数据库在同一时间? [英] Possible for PHP app built on top of codeigniter to connect to a MySQL AND a mongoDB database at the same time?

查看:203
本文介绍了可能的PHP应用程序建立在codeigniter之上连接到MySQL和一个mongoDB数据库在同一时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置在codeigniter中的网络应用程序,并通过,以及如何指定配置组 a>。


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/

  1. Is this possible (using two different types of databases simultaniously -- with/without hacking codeigniter, I would assume it is)

  2. 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...

解决方案

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.

这篇关于可能的PHP应用程序建立在codeigniter之上连接到MySQL和一个mongoDB数据库在同一时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆