php 致命错误:找不到类“MongoDB\Driver\Manager”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38766586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Class 'MongoDB\Driver\Manager' not found
提问by tthlaszlo
I want to use the MongoDB Driver, but it throw me an error, when i use it:
我想使用 MongoDB 驱动程序,但是当我使用它时它给我一个错误:
$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
The error:
错误:
Message: Class 'MongoDB\Driver\Manager' not found
消息:找不到类“MongoDB\Driver\Manager”
When i check it with the php_info(), i see, there is
Is there any requirement to use the driver?
使用驱动程序有什么要求吗?
回答by simon
There is some confusion between the Mongo extension and the MongoDB extension which are not the same. Because of your version number, I guess you are using the old Mongo extension that is deprecated.
Mongo 扩展和 MongoDB 扩展之间存在一些混淆,它们并不相同。由于您的版本号,我猜您正在使用已弃用的旧 Mongo 扩展。
Make sure that you install the new MongoDB extensionand you should be fine. Don't forget to remove the old extension=mongo.so
from your php.ini since this could cause problems.
确保你安装了新的MongoDB 扩展,你应该没问题。不要忘记extension=mongo.so
从 php.ini 中删除旧的,因为这可能会导致问题。
回答by Ryan DuVal
For me, I forgot to add extension=mongodb.so
to the php.ini
for FPM (FastCGI Process Manager). On Ubuntu 16.04 this was at:
对我来说,我忘记添加extension=mongodb.so
到php.ini
FPM(FastCGI Process Manager)。在 Ubuntu 16.04 上,这是在:
/etc/php/7.0/fpm/php.ini
/etc/php/7.0/fpm/php.ini
For what it's worth I'm using nginx.
对于我使用 nginx 的价值。
回答by abhishek kumar
1.Add mongo DB
1.添加mongo数据库
$sudo apt update && sudo apt install php-mongodb
Restart apache server,
check in phpinfo() for mongo
重启apache服务器,
为 mongo 签入 phpinfo()
回答by Kistlak Rajapaksha
If you get this error, even after you installed the Mongodb driver for php, just install mongodb using composer.
如果出现此错误,即使在为 php 安装了 Mongodb 驱动程序之后,也只需使用 composer 安装 mongodb。
composer require mongodb/mongodb
After that this will solve your problem.
之后,这将解决您的问题。
回答by Habib Mammadov
How to install on macOS Mojave
如何在 macOS Mojave 上安装
Start with:
从...开始:
sudo pecl install mongodb
须藤 pecl 安装 mongodb
To check if mongodb package is installed, look for "mongodb" when you run:
要检查是否安装了 mongodb 包,请在运行时查找“mongodb”:
pecl list
目录
To get your installed mongodb.so path, run:
要获取已安装的 mongodb.so 路径,请运行:
pecl list-files mongodb | grep mongodb.so
pecl 列表文件 mongodb | grep mongodb.so
then remove (or comment out) on your php.ini file:
然后删除(或注释掉)你的 php.ini 文件:
extension="mongodb.so"
扩展=“mongodb.so”
(I could not found a line with extension="php_mongodb.so")
(我找不到带有 extension="php_mongodb.so" 的行)
now insert a line with:
现在插入一行:
extension="{{the path to your installed mongodb.so}}"
extension="{{你安装的 mongodb.so 的路径}}"
Run this command to get your ext-*.ini directory path:
运行此命令以获取您的 ext-*.ini 目录路径:
php -i | grep Scan
php -i | 扫描
Create your ext-mongodb.ini with:
使用以下命令创建 ext-mongodb.ini:
touch {{your conf.d path}}/ext-mongodb.ini
触摸 {{你的 conf.d 路径}}/ext-mongodb.ini
like: touch /usr/local/etc/php/7.1/conf.d/ext-mongodb.ini
如:触摸/usr/local/etc/php/7.1/conf.d/ext-mongodb.ini
Restart your apache to read the new configuration
重新启动您的 apache 以读取新配置
Sanity check with:
健全性检查:
php -i | grep mongodb
php -i | grep mongodb
Your're ready to go.
你准备好了。
回答by Shashank
Might be your CLI version of php is different ,check php version in terminal using php -v. and then switch accordingly... FOR EX-:
可能是您的 CLI 版本的 php 不同,请使用 php -v 在终端中检查 php 版本。然后相应地切换...... FOR EX-:
From PHP 7.1 => PHP 5.6
从 PHP 7.1 => PHP 5.6
$ sudo update-alternatives --set php /usr/bin/php5.6.
I hope it will help you guys.
我希望它会帮助你们。