简体   繁体   中英

Fatal error: Class 'Mongo' not found in

I need to use Mongodb in my PHP script.

So I have installed php_mongodb.dll from php_mongodb-1.2.5-5.6-ts-vc11-x64.zip into "C:\\wamp64\\bin\\php\\php5.6.25\\ext\\". I have added extension.dll in php.ini .

When I run php.exe , there is nothing wrong, any warning... But Mongodb doesn't appear in the list of php extensions ( phpinfo() ).

In addition, my index.php returns " Fatal error: Class 'Mongo' not found in C:\\wamp64\\www\\scripts\\index.php on line 47 ". The line 47 : $con = new Mongo(); # localhost:27017 $con = new Mongo(); # localhost:27017

  • Version Apache :2.4.23
  • Version de PHP :5.6.25
  • OS : Windows 10
  • Wamp : Version 3.0.6 - 64bit

I have already tried php_mongodb.dll or php_mongo.dll , different other versions... But now, I have any idea.

If someone has solution to propose, he will be welcome. Thank you in advance.

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...

To whom may concern !

I migrated a system:

  • PHP 5.6 to 7.2
  • Mongo Server 2.6 to 4.4
  • Driver 1.3 to 1.9

Do not replace new Mongo , create an alias instead. This is what I did.

  • Original:
$this->connectionDB = new Mongo('...');
  • Added:
use MongoDB\Driver\Manager as Mongo;

$this->connectionDB = new Mongo('...');

And you don't need to fix anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM