dqkmn26444 2018-10-04 17: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:

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

Also my phpinfo shows this:

php mongodb extension

Also I have included the following:

  1. var_dump(extension_loaded('mongodb'));
  2. echo phpversion('mongodb')."
  3. ";

which have returned:

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

I also have:

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

phpinfo tells me my php.ini file is here:

location of php ini file

And i have added to that:

  1. extension=mongodb.so

In my PHP file I have the following:

  1. require 'vendor/autoload.php'; // include Composer's autoloader
  2. $m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
  3. //$m = new MongoDB\Client("mongodb://localhost:27017");
  4. echo "connected successfully";
  5. // select a database
  6. $db = $m->bob;
  7. 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:

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

Is there anything I could be missing?

展开全部

  • 写回答

1条回答 默认 最新

  • douzheng9221 2018-10-04 22:49
    关注

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

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

    评论
    编辑
    预览

    报告相同问题?

    悬赏问题

    • ¥15 MC9S12XS128单片机实验
    • ¥15 失败的github程序安装
    • ¥15 WSL上下载的joern在windows怎么用?
    • ¥15 jetson nano4GB
    • ¥15 电脑回复出厂设置,重装过程报错提示,求解决方案Windows 无法分析或处理无人参与应答文件 [C:\WINDOWS\Panther\unattend.xml,如何解决?
    • ¥15 进入lighttools中的UDOP编辑器的方法
    • ¥15 求Gen6d训练数据集
    • ¥20 liunx中winscp中可以登入ftp,但是不能登入sftp,如何解决
    • ¥15 lighttools的光学属性自定义的用法流程
    • ¥15 uni-app动态修改推荐页标题时报错
    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部