0

Recently I upgraded my Wamp server from Wamp 2.5 to Wamp 3.0 succesfully. Now, in my Wamp 3.0 server, PHP is at version 5.6.31.

I downloaded the MongoDB driver (stable version 1.2.10) from https://pecl.php.net/package/mongodb, and installed it successfully into my Wamp server. The server shows mongodb as one of the loaded extensions.

I encountered an error message: Fatal error: Class 'MongoClient' not found in C:\wamp64\www\loginNew.php on line ...

That PHP code ran perfectly in the previous version of Wamp (and PHP). Here is the code

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

// select a database
$db = $m->ConsentForm;

$collection = $db->ConsentFormDetail;     

$agreeBoolean           = $_POST['agree']; 
$nameInitial            = $_POST['initial']; 
$informedBoolean        = $_POST['informed']; 
$email                  = $_POST['emailAddress']; 



    $consentForm = array( 
          "agreeBoolean"            => $agreeBoolean, 
          "nameInitial"             => $nameInitial,
          "timeOfSigning"           => date("Y-m-d H:i:s"),
          "informed"                => $informedBoolean,
          "email"                   => $email                 
       );
    $collection->insert($consentForm);
    echo "You have Successfully Signed the consent form.....";


?>

After some search, I replaced

$m = new MongoClient();

with

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

Then the following error message occured: Notice: Undefined property: MongoDB\Driver\Manager::$MergedParticipant in C:\wamp64\www\loginNew.php on line ...

Can you please help,

Many thanks

1

1 Answer 1

0

To use MongoDB with PHP, you need to use MongoDB PHP driver. Download the driver from the url Download PHP Driver. Make sure to download the latest release of it. Now unzip the archive and put php_mongo.dll in your PHP extension directory ("ext" by default) and add the following line to your php.ini file −

extension = php_mongo.dll

tutorialspoint.com/mongodb/mongodb_php.html please refer this link for connect mongodb with php –

Sign up to request clarification or add additional context in comments.

3 Comments

Yeah, I did all the above steps, so that Wamp server showed the MongoDB has been installed successfully. I however want to know why the MongoClient() class not found.
tutorialspoint.com/mongodb/mongodb_php.htm please refer this link for connect mongodb with php
Thanks for your comment. However, this link is for the older version of PHP i guess. My code worked well in this version, but it doesn't in the newer version of PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.