问题描述
我想从php
运行mongo
,我正在使用MongoDB 64 bit
,WampServer 64 bit
,Apache Version:2.4.18
和PHP Version: 5.6.19
.我还在PHP
的php.ini
和apache
的php.ini
中添加了mongodb.dll
扩展名.我还安装了Composer
并运行命令
I want to run mongo
from php
I am using MongoDB 64 bit
, WampServer 64 bit
, Apache Version:2.4.18
and PHP Version: 5.6.19
. I also added mongodb.dll
extension in php.ini
of PHP
as well as in php.ini
of apache
. I have also installed Composer
and run the command
composer require "mongodb/mongodb=^1.0.0"
在运行下面的代码时,出现此错误:
On running the code below I am getting this error:
与mongo的连接成功,并且还选择了db,那么为什么会出现此错误?
Connection to mongo is successful and db is also selected then why this error?
require 'vendor/autoload.php';
// connect to mongo
$m = new MongoDB\Driver\Manager();
echo "Connection to database successfully";
// select a db
$db = $m->mydb;
echo "Database mydb selected";
?>
我也尝试了$db = $m->test;
,但是遇到了同样的错误.预先感谢您的帮助.
I also tried $db = $m->test;
but getting the same error. Thanks in advance for any help.
推荐答案
通过添加
$m = new MongoDB\Client("mongodb://localhost:27017");
代替
$m = new MongoDB\Driver\Manager();
实际上,我上错了课. :)
Actually, I was calling the wrong class. :)
这篇关于注意:wamp服务器中[Path]中的未定义属性:MongoDB \ Driver \ Manager :: $ mydb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!