Fatal error: Class 'MongoDB\Driver\Manager' not found
There is some confusion between the Mongo extension and the MongoDB extension which are not the same. Because of your version number, I guess you are using the old Mongo extension that is deprecated.
Make sure that you install the new MongoDB extension and you should be fine. Don't forget to remove the old extension=mongo.so
from your php.ini since this could cause problems.
MongoDB\Driver\Manager' not found with php
"Console" and "Web" are using two different PHP binaries (and configurations).
Put the extension=php_mongodb.dll
also in the so called php-cli
version php.ini
and the problem should be solved.
Class 'MongoDB\Driver\Manager' not found Even if php-mongo has been installed
I didn't solve the problem eventually. But I removed built-in apache2
and PHP
then reinstalled them by brew
instead. This time I chose apache24
and php70
, also turned to php70-mongodb
rather than 5.5's.
By the way, I'm sure that is the problem caused by the package not being installed correctly or setting wrong. But I didn't solve problem toward that way. I chose another (install other versions) instead.
1. Remove built-in apache
Let apache stopsudo apachectl stop
Remove built-in apachesudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
2. Install packages by Homebrew
Install apache (apache is calledhttpd
)brew install httpd24
Install php 7brew install php70 --with-apache
Install PHP driver of MongoDBbrew install php70-mongodb --with-apache
3. Restart apache
sudo apachectl restart
Class 'MongoDB\Driver\Manager' not found (extension not loaded)
Solution: I was using a 64-bit dll which was incompatible with the 32-bit xampp which was running php. Simply remove the 64-bit dll and download the 32-bit version.
Class 'MongoDB\Client' not found, mongodb extension installed
If you are using latest MongoDB extension of PHP, MongoDB\Driver\Manager
is the main entry point to the extension.
Here is the sample code to retrieve data using latest extension.
Let's say you have testColl
collection in testDb
. The you can retrieve data using MongoDB\Driver\Query
class of the extension.
// Manager Class
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));
// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $manager->executeQuery('testDb.testColl', $query);
// Convert cursor to Array and print result
print_r($cursor->toArray());
Output:
Array
(
[0] => stdClass Object
(
[_id] => MongoDB\BSON\ObjectID Object
(
[oid] => 5848f1394cea9483b430d5d2
)
[name] => XXXX
[age] => 30
)
)
Related Topics
MySQL Alter Table Add Field Before or After a Field Already Present
Execute a PHP Script from Another PHP Script
I Have a Base64 Encoded Png, How to Write the Image to a File in PHP
Codeigniter - File Upload Required Validation
Codeigniter Assets Folder Best Practice
Arabic Characters in JSON Decoding
How to Convert Object into String in PHP
How to Select Rows Where Column Value Is Not Null Using Codeigniter's Activerecord
Difference Between Eloquent\Model::Get() and All()
Change Name of Laravel's Created_At and Updated_At
How to Set Session Timeout in Laravel
PHP Pdo Insert Batch Multiple Rows with Placeholders
Running Imagemagick on Xampp 1.8.3 with Windows 7
Designing a Secure Auto Login Cookie System in PHP
Woocommerce - Send Custom Email on Custom Order Status Change