Hey everyone, I’ve encountered a bit of a problem following along with the offical docs here.
Error: Class 'MongoDB\Client' not found in C:\xampp\htdocs\mongo.php on line 6
My code
I was unable to get the Mongo extension installed using PECL (tells me that it doesn’t exist) so I had to install it manually. I have confirmed it’s installed correctly:
php --ri mongodb
mongodb
MongoDB support => enabled
MongoDB extension version => 1.9.0
MongoDB extension stability => stable
libbson bundled version => 1.17.2
libmongoc bundled version => 1.17.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
libmongoc ICU => disabled
libmongoc compression => disabled
libmongocrypt bundled version => 1.0.4
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto
Directive => Local Value => Master Value
mongodb.debug => no value => no value
Next I installed the mongodb library via composer and confirmed it’s been added correctly:
composer show mongodb/mongodb
name : mongodb/mongodb
descrip. : MongoDB driver library
keywords : database, driver, mongodb, persistence
versions : * 1.8.0
type : library
license : Apache License 2.0 (Apache-2.0) (OSI approved) https://spdx.org/licenses/Apache-2.0.html#licenseText
homepage : https://jira.mongodb.org/browse/PHPLIB
source : [git] https://github.com/mongodb/mongo-php-library.git 953dbc19443aa9314c44b7217a16873347e6840d
dist : [zip] https://api.github.com/repos/mongodb/mongo-php-library/zipball/953dbc19443aa9314c44b7217a16873347e6840d 953dbc19443aa9314c44b7217a16873347e6840d
path : C:\git\waw\vendor\mongodb\mongodb
names : mongodb/mongodb
support
issues : https://github.com/mongodb/mongo-php-library/issues
source : https://github.com/mongodb/mongo-php-library/tree/1.8.0
autoload
psr-4
MongoDB\ => src/
files
requires
ext-hash *
ext-json *
ext-mongodb ^1.8.1
jean85/pretty-package-versions ^1.2
php ^7.0 || ^8.0
symfony/polyfill-php80 ^1.19
requires (dev)
squizlabs/php_codesniffer ^3.5, <3.5.5
symfony/phpunit-bridge 5.x-dev
I’m not sure what the issue is at this point. It’s possible something is wrong with the autoloader, so I dumped it and had composer regenerate it. No dice. Do you guys have any thoughts on what the cause might be?
I’m running php 7.4 on Windows 10 via XAMPP.