“MongoDB \ Client”或“MongoDB \ Driver \ Manager”(“mongodb:// localhost:27017”)都不起作用

I am trying to install the mongoDB extension for PHP with MAMP so I can potentially access my MongoDB server, and as far as I can tell, I have done everything right, yet I am still getting errors.

I have the MongoDB extension installed - I can tell because:

$sudo pecl install mongodb
pecl/mongodb is already installed and is the same as the released version 1.5.3
install failed

Also my phpinfo shows this:

php mongodb extension

Also I have included the following:

var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."
";

which have returned:

/Applications/MAMP/htdocs/mongo.php:35:boolean true
1.5.3 

I also have:

$ composer require mongodb/mongodb
Using version ^1.4 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

phpinfo tells me my php.ini file is here:

location of php ini file

And i have added to that:

extension=mongodb.so

In my PHP file I have the following:

require 'vendor/autoload.php'; // include Composer's autoloader
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
//$m = new MongoDB\Client("mongodb://localhost:27017");

echo "connected successfully";

// select a database
$db = $m->bob;
echo "database selected";

If I try the MongDB/Client option, I get the following error:

Fatal error: Uncaught Error: Class 'MongoDB\Client' not found in /Applications/MAMP/htdocs/mongo.php on line 61

If I try the MongoDB/Driver option, I get the following error:

Notice: Undefined property: MongoDB\Driver\Manager::$bob in /Applications/MAMP/htdocs/mongo.php on line 52

A var_dump of MongoDB\Driver etc. gives the following:

 /Applications/MAMP/htdocs/mongo.php:38:
 object(MongoDB\Driver\Manager)[3]
 public 'uri' => string 'mongodb://localhost:27017' (length=25)
 public 'cluster' => 
    array (size=0)
    empty

Is there anything I could be missing?

1个回答



您是否已将 extension = mongodb.so </ code>添加到php.ini文件中?</ p>

这是我在此处未列出的唯一信息。</ p>
</ div>

展开原文

原文

have you added extension=mongodb.so to your php.ini file ?

that is the only information i do not see listed here.

duanboniao5903
duanboniao5903 不确定是否允许,但我已经尝试了一些替代代码,我相信这是更进一步,但有一个新问题,我在这里问:stackoverflow.com/questions/52669717 / ...
接近 2 年之前 回复
dousa2794
dousa2794 哦,是的。 (忘了看mongodb版本)然后我不能帮助你进一步思考。 也许可以尝试一个指南或者其他东西来创建一个测试项目,这样你就可以比较一个与之相对的那个。
接近 2 年之前 回复
dsf11t5u1651
dsf11t5u1651 这不是被弃用了吗? mongodb然后从我的phpinfo中消失,它现在说没有找到Class'MongoDB \ Driver \ Manager'。
接近 2 年之前 回复
duanliang2017
duanliang2017 你可以尝试mongo.so而不是mongodb.so。 它可能有所帮助(不一定不确定)
接近 2 年之前 回复
dongtaochan0777
dongtaochan0777 是的,对不起,我也有。 我将添加有关上述信息。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问