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

Khoi Boo
  • 45
  • 6
  • Please check my answer which may help you for the question : why the MongoClient() class not found. https://stackoverflow.com/a/46324135/1696621 – Channaveer Hakari Sep 20 '17 at 14:06

1 Answers1

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 –

Suhag Lapani
  • 655
  • 10
  • 18
  • 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. – Khoi Boo Sep 14 '17 at 15:05
  • https://www.tutorialspoint.com/mongodb/mongodb_php.htm please refer this link for connect mongodb with php – Suhag Lapani Sep 14 '17 at 15:19
  • 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 – Khoi Boo Sep 14 '17 at 17:28