Class mongodb driver manager not found yii2

I am using php7.1.5[latest] and add mongodb extension with the help of below link //php.net/manual/en/mongodb.installation.windows.php. Using mongodb driver version as 1.2.9 add dll file in php/ext folder. I check phpinfo[] mongodb extension is added. But when i access mongodb like below

$mng = new MongoDB\Driver\Manager["mongodb://localhost:27017"];

It will throw error like MongoDB\Driver\Manager' not found.

I try to add mongodb extension in php.ini file like below formats, but it will not work

extension=php_mongodb.dll, extension=mongodb.dll

i am using apache version 2.4.25

asked May 19, 2017 at 7:20

2

Add a backslash in front, as the class is in the Global Namespace and not under yii

$mng = new \MongoDB\Driver\Manager["mongodb://localhost:27017"];

answered May 22, 2017 at 9:20

1

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Pick a username Email AddressPassword

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am creating REST APi with Lumen framework. I use Mongolab for my mongoDB and i want to host my app on google App Enginge. I am using Jessenger lib for communicating with my DB on MongoLab. Everhting is okay when I run the app localy but when I deploy on GAE I get

Fatal error: Class 'MongoDB\Driver\Manager' not found in /base/data/home/apps/s~lumentestapi/v1.391053224987814328/ vendor/mongodb/mongodb/src/Client.php on line 56

I have enabled

extension = mongo.so

in the php.ini located in root.

Any help how can I fix this?

techraf

4,77211 gold badges23 silver badges39 bronze badges

asked Feb 29, 2016 at 23:28

Are you using the new mongodb driver rather than the mongo driver?

If so you should use:

extension=mongodb.so

in your php.ini file instead.

[I had that issue myself recently while upgrading our servers]

techraf

4,77211 gold badges23 silver badges39 bronze badges

answered Mar 9, 2016 at 0:35

If you're using PHP7.*. with Ubuntu, you can do the following:

sudo apt update && sudo apt install php-mongodb

This assumes you installed the library via composer require mongodb/mongodb

Then remember to restart your app's server. Check phpinfo[] for mongo.

answered Apr 17, 2019 at 0:09

JonathanJonathan

3811 gold badge3 silver badges20 bronze badges

1

Make sure you init driver class as below

$manager = new MongoDB\Driver\Manager["mongodb://localhost"];
$collection = new MongoDB\Collection[$manager, "logs","capped_logs"];

answered Jun 15, 2016 at 18:19

Chủ Đề