简体   繁体   中英

PHP MongoDB: Fatal error: Class 'MongoClient' not found in wamp

Hi I have been trying to connect to mongodb from php. I am using the below dll:

php_mongo-1.6.8-5.5-vc11-x86_64.dll

I was going through one of the threads on stackoverflow PHP MongoDB: Fatal Error: Class 'Mongo CLient' not found ,which mentions that MongoClient() class has been deprecated. Instead of it now we need to use something like this:

$m = new MongoDB\Driver\Manager();

I have the following code:

<?php
$m = new MongoDB\Driver\Manager();
$db = $m->testdb;
echo "Connected to db";
?>

Still I am getting error for class not found. Does anyone have any idea about it? Or do I have to import something? Please help.

It is possible that \\ is missing at the time of object creation.

 $m = new \MongoClient();

or

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

The error you are getting might be due to the namespace issue. Try both the solutions one by one and see if it helps.

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