Skip to content


PHP MongoDB: Fatal error: Class ‘MongoClient’ not found

 

When executing following PHP code:

$m = new MongoClient("mongodb://localhost:27017");

I get following error:

Fatal error: Class ‘MongoClient’ not found in (…)

MongoDB extension seems properly installed (I copied php_mongodb.dll to ext folder and updated php.ini).

PHP seems to confirm that extension is running properly as the following code confirms it is loaded:

echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";

Also, phpinfo() shows that mongodb extension has been loaded.

UPDATE

Problem still not solved.

phpinfo() clearly shows that the driver is loaded:

enter image description here

TL; DR

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

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.

Posted in datatable. Tagged with , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.