douye2020 2012-06-23 22:47
浏览 50

建立一个简单的mongohq连接

Is there a way to establish a connection to a cloud mongoDB (such as mongoHQ), with no drivers or third party apps, from a localhost server?

In other words, I want to host my php files locally, and connect to a mongoDB on the cloud.

I've been doing simple websites using php and MySQL as a hobbie for a few years, and I'm pretty decent at it, but I haven't been able to figure out how to do this one simple thing with Mongo.

Whenever I run a file that does:

$m = new Mongo('mongodb://username:password@staff.mongohq.com:XXXXX/database');

from a php file, I get a HTTP 500 error.

Any help would be greatly appreciated. In advance I apologize if this isn't clear enough, this is my first post on SO. Please let me know if more info is needed.

  • 写回答

1条回答 默认 最新

  • douwen3500 2012-06-23 23:34
    关注

    Have you looked at your PHP/apache error log to see what the HTTP 500 error is ? Try adding to the top of your script:

    ini_set('display_errors',1); 
    error_reporting(E_ALL);
    

    Based on your code sample, I would check that you have the Mongo module installed as it will generally not be included by default. Use phpinfo() and look for the mongo section.

    If you want to use MongoHQ without installing a Mongo driver, you could also try their REST API which apparently is still in beta phase.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题