PHP 中的 mongodb 服务

发布于 2024-11-17 15:39:59 字数 369 浏览 8 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兲鉂ぱ嘚淚 2024-11-24 15:39:59

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?

毁梦 2024-11-24 15:39:59

感谢您的回答和评论,我修复了。

问题出在服务命令行中,我使用此命令

"C:\mongodb\bin\mongod" --bind_ip 127.0.0.1 --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install 

而不是

"C:\mongodb\bin\mongod" --bind_ip myIPadress --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install

在 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

"C:\mongodb\bin\mongod" --bind_ip 127.0.0.1 --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install 

instead of

"C:\mongodb\bin\mongod" --bind_ip myIPadress --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install

In the php code new Mongo("mongodb://".$_host.":".$_port,true) , $host = myIPadress

That 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()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文