PHP MongoDB: Fatal error: Class 'MongoClient' not found -
when executing following php code:
$m = new mongoclient("mongodb://localhost:27017");
i following error:
fatal error: class 'mongoclient' not found in (...)
mongodb extension seems installed (i copied php_mongodb.dll ext folder , updated php.ini).
php seems confirm extension running following code confirms loaded:
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
also, phpinfo()
shows mongodb extension has been loaded.
update
problem still not solved.
phpinfo()
shows driver loaded:
but still receive same fatal error.
tl; dr
the class mongoclient
part of legacy pecl package mongo not anymore of up-to-date mogodb package.
on mongodb php driver github repo, release note version 1.0.0, suggesting developers use mongodb\driver\manager
instead of mongoclient
changes our legacy mongo extension
most significantly, legacy driver's mongoclient, mongodb, , mongocollection classes have been obsoleted mongodb\driver\manager class, new gateway connecting , executing queries, commands, , write operations.
source: https://github.com/mongodb/mongo-php-driver/releases/tag/1.0.0
as documentation prompting it, class deprecated.
warning extension defines class deprecated. instead, mongodb extension should used. alternatives class include:
- mongodb\driver\manager
source: http://php.net/mongoclient
from read on github repository release history, class trying use have been obsoleted since version of mongodb 1.0.0
, so, on version 1.6.0
are, class not part of dll
anymore.
that confirmed this issue on github
derickr commented on apr 16
mongoclient class old legacy driver , not supposed available in one. new driver has \mongodb\driver\manager, and, accompanying library has \mongodb\client.
you either need install old legacy extension (pecl install mongo) , use php 5.x, or update code use new driver's classes old driver not available php 7. there upgrade guide @ http://mongodb.github.io/mongo-php-library/upgrade-guide/
source : https://github.com/mongodb/mongo-php-driver/issues/300#issuecomment-210820288
here the replacement class documentation , snippet of code should replace yours :
$m = new mongodb\driver\manager("mongodb://localhost:27017");
another way, suggested mongodb member quoted here above use pecl extension: https://pecl.php.net/package/mongo instead of https://pecl.php.net/package/mongodb please notice warning there stating:
this package has been superseded, still maintained bugs , security fixes.
Comments
Post a Comment