Search code examples
mongodbwampserverphp-mongodb

PHP is not connecting with mongoDB


Currently i'm working in a web project which requires php & mongoDB.when i run the code it gives error

These are the technologies i have used

wampserver 3.1.7

apache 2.4.37

php 7.2.14

mongoDB 4.20

mongo-php driver 7.2 thread safe(Ts) x64

& i'm using windows 8.1 (64-bit) operating system

what i have did was:

installed mongodb on C:\Program Files

installed wampserver on C:\

changed C:\Program Files\MongoDB\Server\4.2\bin as an environment path

put php_mongodb.dll in C:\wamp64\bin\php\php7.2.14\ext folder

add "extension=php_mongodb" this line in php.ini

restarted the wamp server

//this is my code
<?php
$m=new MongoClient();
?>

my mongodb and wampserver is working properly..i can find mongodb in 'Loaded Extensions' in wampserver homepage..

when i run the code it says:

( ! )Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\wamp64\www\all_files\mongo.php on line 2 ( ! ) Error: Class 'MongoClient' not found in C:\wamp64\www\all_files\mongo.php on line 2

please help me whats gone wrong..tell me how can i connect php with mongoDB

Thank you!!!


Solution

  • It looks like you either have a bad installation of mongoDB, or you are running an incompatible version of mongoDB.

    If SQL is an alternative then that is always a great option.

    In the worst of cases you can still work with encrypted files with PHP.

    double check the system path

    i have had similar experience in the past, that happened either to a poor installation or broken registry items.

    I highly suggest at least attempting this on a unix like platform if your processor allows for a virtual machine , or dual booting.

    that aside, the only thing i can think off is reinstalling xampp.

    ========= things to consider

    are you running the application as admin?

    can you use sql as an alternative?

    is your firewall conflicting with the connection to the server?

    do you have any firewall rules conflicting with the connection to the server?

    is mongoDB properly installed?