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 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?