1

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.

aman
  • 73
  • 1
  • 9
  • I have placed the dll in C:/wamp/php/php5.5.12/ext/ and mentioned the name of the extension as well in php.ini file with the following statement : extension=php_mongo-1.6.8-5.5-vc11-x86_64.dll I have also restarted the wamp server. I do not understand what is the problem. – aman Sep 29 '17 at 23:50
  • @endo64 any idea on this – aman Sep 29 '17 at 23:54
  • @b.enoit.be please help – aman Sep 29 '17 at 23:57

1 Answers1

0

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.

Kamal Soni
  • 1,522
  • 13
  • 15