PHP 中的 mongodb 服务
我正在尝试在 php 中连接到 mongodb。 如果 mongodb 在 shell 中使用 mongod 命令启动,就没有问题。
new Mongo("mongodb://".$_host.":".$_port,true)
但是当我将 mongodb 服务器作为服务启动时,我可以使用 mongo 命令连接,但无法在 php 中连接。
new Mongo("mongodb://".$_host.":".$_port,true)
还有其他论据吗? 我正在使用最新版本的 mongodb 和最新版本的 php。
有人可以帮助我吗?
I'm trying to connect to mongodb in php.
There's no problem if mongodb is start in shell with mongod command.
new Mongo("mongodb://".$_host.":".$_port,true)
But when i start mongodb server as a service, i can connect with the mongo command, but i cant connect in php.
new Mongo("mongodb://".$_host.":".$_port,true)
Is there any other arguments?
I'm using the last version of mongodb and the last version of php.
Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MongoDB 服务的命令行参数是什么?您是否可能指定了与手动运行 mongod 时默认获得的配置不同的配置?您使用哪些参数来安装 MongoDB 作为服务?
What are your command line parameters for the MongoDB service? Is it possible that you've specified a different configuration than what you get by default when manually running mongod? What parameters did you use to install MongoDB as a service?
感谢您的回答和评论,我修复了。
问题出在服务命令行中,我使用此命令
而不是
在 php 代码中
new Mongo("mongodb://".$_host.":".$_port,true)
, $ host = myIPadress这就是为什么它在命令行中工作而不是在 php 代码中工作,它必须是相同的 IPadress,如果您不使用默认的
new Mongo()<,请不要使用 localhost 或类似的东西/代码>
Thanks for your answer and comment, i fix it.
The problem was in the service command line , i use this command
instead of
In the php code
new Mongo("mongodb://".$_host.":".$_port,true)
, $host = myIPadressThat why it was working in command line and not in the php code, it must be the same IPadress, don't use localhost or something like that if you don't use a default
new Mongo()