Fatal Error - 'Mongo' Class Not Found

Fatal Error - 'Mongo' class not found

The problem was the PHP driver (php_mongo.dll). Apache/WAMP just did not like the mongo-1.1.4-php5.3vc6ts version for some reason. My Windows 7 Professional machine had the mongo-1.2.5-php5.3vc9ts version. That was the only difference between the two machines.

I originally had been using the mongo-1.2.5-php5.3vc9ts version of the driver on the Windows 7 Enterprise machine but changed to the mongo-1.1.4-php5.3vc6tsversion when I was troubleshooting the problem. So the original problem could actually just have been that the database path data\db didn't exist/couldn't be found (and needed to be specified using --dbpath when running/starting mongod.exe).

Fatal error: Class 'Mongo' not found in

Finally, I found a solution... The right dll !

In fact, I must use MongoDB PHP Driver on Windows.
Then add extension=php_mongodb.dll into php.ini.
And download the corresponding file from mongodb 1.2.5, in this case 5.6 Thread Safe (TS) x64.

php.exe shows no warning and the line 47 ($con = new MongoDB\Driver\Manager("mongodb://localhost:27017"); # localhost:27017) works correctly.

Don't forget to restart services.

Hopefully this solution will serve...

MongoDB: Fatal error: Class 'MongoClient' not found

TL;DR

The class MongoClient is part of the legacy PECL package mongo but not anymore of the up-to-date mongodb package.

And since you have the mongodb extension installed, and not the mongo one, this is why you are getting the error

Fatal error: Class 'MongoClient' not found

On MongoDB PHP driver github repo, the release note about the version 1.0.0, is suggesting developers to use MongoDB\Driver\Manager instead of MongoClient

Changes from our legacy mongo extension

Most significantly, the legacy driver's MongoClient, MongoDB, and
MongoCollection classes have been obsoleted by the
MongoDB\Driver\Manager class, which is the new gateway for connecting
and executing queries, commands, and write operations.

Source:: https://github.com/mongodb/mongo-php-driver/releases/tag/1.0.0

So, here is the replacement class documentation and the snippet of code that should replace yours :

$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");

As the documentation is prompting it, the class is deprecated.

Warning This extension that defines this class is deprecated. Instead,
the MongoDB extension should be used. Alternatives to this class
include:

  • MongoDB\Driver\Manager

Source: http://php.net/MongoClient


From what I read on their github repository release history, the class you are trying to use have been obsoleted since the version of mongodb 1.0.0, so, on the version 1.6.0 you are, this class is not even part of the dll anymore.

That is confirmed by this issue on their github

derickr commented on Apr 16

MongoClient is a class from the old legacy
driver and is not supposed to be available in this one. The new driver
has \MongoDB\Driver\Manager, and, the accompanying library has
\MongoDB\Client.

You either need to install the old legacy extension (pecl install
mongo) and use PHP 5.x, or update your code to use this new driver's
classes as the old driver is not available for PHP 7. There is an
upgrade guide at
http://mongodb.github.io/mongo-php-library/upgrade-guide/

Source: https://github.com/mongodb/mongo-php-driver/issues/300#issuecomment-210820288


Another way, as suggested by the MongoDB member quoted here above is to use this pecl extension: https://pecl.php.net/package/mongo instead of https://pecl.php.net/package/mongodb but please also notice the warning there stating:

This package has been superseded, but is still maintained for bugs and security fixes.

Fatal error: Class 'MongoDB\Driver\Manager' not found

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.

Make sure that you install the new MongoDB extension and you should be fine. Don't forget to remove the old extension=mongo.so from your php.ini since this could cause problems.

WAMPServer Fatal error: Class 'Mongo' not found

Had the same issue. Below steps solved my issue.

  1. Make sure you have a 32 bit WAMP setup in place. Apparently, there are problems with 64 bit
  2. Get the lates php_mongo driver from https://github.com/mongodb/mongo-php-driver/downloads compatible with your version
  3. Rename it to php_mongo.dll and copy it to php extenstions folder. Default on windows is "ext"
  4. check phpinfo()
  5. Check for Loaded Configuration File variable. It gives you the path from where the php.ini file is read
  6. Add the line extension=php_mongo.dll to the php.ini file in the above path
  7. Restart your services


Related Topics



Leave a reply



Submit