为什么我的MongoClient()会出错?

时间:2014-08-05 14:18:14

标签: mongodb mongodb-php

其实我是这个mongodb的新手。

这里mongo在localhost和phpinfo()上可见。对

http://127.0.0.1:27017/

也变得像#34;看起来你正试图在本机驱动程序端口上通过HTTP访问MongoDB。" 。 从命令提示符也可以运行mongo。

但是在程序中使用Mongo()/ MongoClient时仍然会出错。

Deprecated: main(): The Mongo class is deprecated, please use the MongoClient class in C:\wamp\www\mongo\new.php on line 2

Fatal error: Uncaught exception 'MongoConnectionException' with message ' in C:\wamp\www\mongo\new.php on line 4
( ! ) MongoConnectionException: Failed to connect to: example.com:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\mongo\new.php on line 4

我如何解决这些问题?

1 个答案:

答案 0 :(得分:1)

这个错误通常是在使用已经被MongoClient类替换的已弃用的Mongo类时引起的,新的MongoClient类要求您先创建一个像$m = new MongoClient();这样的连接,之前使用它将具有的旧类看起来像$m = new Mongo();

如果您想详细了解http://php.net/manual/en/class.mongoclient.php