T. Ato
T. Ato

Reputation: 143

Class 'Mongo' not found in XAMPP 64-Bit Windows 10

I'm trying to run the following code from on my localhost:

<?php

  $dbhost = 'localhost';
  $dbname = 'phpTest';

  $m = new Mongo("mongodb://$dbhost");
  $db = $m->$dbname;

?>

And get the error, "Fatal error: Class 'Mongo' not found in C:\xampp\htdocs\key_ratios\mongo_test.php on line 6"

MongoDB is properly installed/recognized by PHP

I've restarted Apache several times and MongoDB is running as a service. Mongo's directory path is C:\mongodb\bin. PHP is in C:\xampp\php.

The following are PATH variables: C:\xampp\php, C:\mongodb\bin, C:\Program Files (x86)\Microsoft VS Code\bin, C:\Users[redacted]\AppData\Local\atom\bin.

Any idea why I can't get PHP to connect to Mongo?

Edit: I should note that my mongodb listingin phpinfo() is not nearly as filled out as this one. Does this mean my mongodb isn't fully installed?

Upvotes: 1

Views: 633

Answers (1)

T. Ato
T. Ato

Reputation: 143

I was using the wrong syntax to connect. Should be (with PHPLIB):

new MongoDB\Client("mongodb://localhost:27017");

or (with just the PECL driver): new MongoDB\Driver\Manager("mongodb://localhost:27017");

The documentation is really helpful.

Upvotes: 1

Related Questions