本文介绍了注意:wamp服务器中[Path]中的未定义属性:MongoDB \ Driver \ Manager :: $ mydb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从php运行mongo,我正在使用MongoDB 64 bitWampServer 64 bitApache Version:2.4.18PHP Version: 5.6.19.我还在PHPphp.iniapachephp.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:03