0

I imported the proper mongodb.dll file in php/ext and also configured php.ini but it seems that I can't connect to mongodb via my php code. Example

<?php
   // connect to mongodb
   $m = new MongoClient();

   echo "Connection to database successfully";
   // select a database

?>

Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\xampp\htdocs\date\include\db2.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\date\include\db2.php on line 3

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • Did you install mongoDB? Just like you need MySQL server installed you also need the mongo DBMS installed – RiggsFolly Feb 18 '18 at 15:28
  • Hey @RiggsFolly I installed it, I am good in mongodb but this things seems weird in my new system. That's why raised here. –  Feb 18 '18 at 15:30
  • Is this any use to you https://stackoverflow.com/questions/24533938/class-mongoclient-not-found – RiggsFolly Feb 18 '18 at 15:32
  • The plugin is not loaded, I seen this post before @RiggsFolly and should it be php_mongo.dll or php_mongodb.dll –  Feb 18 '18 at 15:38
  • What version of PHP? – RiggsFolly Feb 18 '18 at 15:44
  • Did you loook at the output from `phpinfo()` – RiggsFolly Feb 18 '18 at 15:45
  • Version 7.2.1, I think this is causing the issue. As some class is depreciated, but I don't know exactly which is causing the issues. –  Feb 18 '18 at 15:52
  • Are you sure this is not what you are looking for https://stackoverflow.com/a/38007889/2310830 – RiggsFolly Feb 18 '18 at 15:55
  • @RiggsFolly the problem is with the php version where the class mongoclient is depreciated as my update my system, I forget to check the php version is compatible, so used the composer to install the mongo library then loaded and everything works fine. –  Feb 18 '18 at 16:44
  • Post an answer and then this question will be useful to someone else. – RiggsFolly Feb 18 '18 at 17:30

0 Answers0