drk49438 2013-05-28 22:10
浏览 37
已采纳

xampp mongoDB连接

I want to make a php app that uses Mongodb.
When I run the app on the localhost I get this:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: 127.0.0.1:27017: Timed out after 1000 ms'

My code is:

<?php  
// Config  
$dbhost = 'localhost';  
$dbname = 'test';  

// Connect to test database  
$m = new Mongo("mongodb://$dbhost");  
$db = $m->$dbname;  

// select the collection  
$collection = $db->shows;  

// pull a cursor query  
$cursor = $collection->find();  
foreach($cursor as $document) {  
var_dump($document);  
}     
?>  
  • 写回答

2条回答 默认 最新

  • doujiao9574 2013-05-30 12:27
    关注

    Enable it in your php.ini file and ensure your using the correct file in the extension directory.

    Use phpinfo() to find if it is enabled.

    If you still have trouble ensure that you are using the correct version of the Mongo driver.. http://docs.mongodb.org/ecosystem/drivers/php/

    You will need to ensure your using the right version x86 or x64 and thread safe / non thread safe.

    You will also be able to find that out from your phpinfo().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码