I tried to create new mongo connection executing the following code
$m = new MongoDB\Client();
and i got this error:
Fatal error: Class 'MongoDB\Client' not found
i think i have properly installed MongoDB extension (Copied php_mongodb.dll to ext folder and updated php.ini with extension=php_mongodb.dll).
The following code confirms it is loaded:
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
I still receive the same error.
Here is phpinfo()
I appreciate all your help. Thank you!
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
)
)
Different for Apache and Nginx it appears.
Though this post is old but I help this migh help someone. I recently ran into same problem. With me it was s different php.ini.
I kept placing the mongoextension into /cli/php.ini.
Thoough when I ran <?php phpinfo() ?>
I found out that in my case the loaded configuration is in /fpm/php.ini. This was because I was unsing Nginx with fpm.
I'm using PHP 7.1.9 and I had this issue. Solved it by removing and reinstalling mongodb/mongodb
composer remove mongodb/mongodb
composer require mongodb/mongodb
Also, If you are using Dreamweaver, don't for get to put the vendor
folder in the server copy.
After installing, I can now use MongoDB\Client
.
mongodb API Version 1.3, Mongodb Extension 1.4
same happened with me, check the version of php install on your server. You have to use php version 5.6 .Check the apche error log to get more precise error detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With