dqkmn26444 2018-10-05 01:57
浏览 242

“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条回答

  • douzheng9221 2018-10-05 06:49
    关注

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料