Mongodb extension not found in PHP 5.6

Asked

Viewed 319 times

1

I am developing an application in PHP 5.6 with Laravel 5.2 using Mongodb.

The problem arose when I decided to upgrade my Mac to El Captam in a clean installation, because when I installed PHP 5.6 with Brew along with the Mongodb extension, the class \MongoDB does not exist, despite appearing in the phpinfo() the version of drive Mongo 1.1.6.

I wonder what’s going on?

I managed to instantiate the class MongoDB\Driver\Manager, but the commands are totally different from the class I used.

I will have to migrate my application to this new driver?

1 answer

1


When using Mongodb with PHP we have to keep in mind that there are two versions of drivers.

We have the extension mongo and the extension mongodb, the second being the latest version.

The driver you will use depends on the version of PHP and Mongodb you are using.

See which to choose according to the tables extracted from the mongodb documentation:

 PHP Driver                 | MongoDB 2.4   | MongoDB 2.6   | MongoDB 3.0   | MongoDB 3.2   
--------------------------  |-------------  |-------------  |-------------  |-------------  
 PHPLIB 1.0 + mongodb-1.1   | X             | X             | X             | X             
 mongodb-1.1                | X             | X             | X             | X             
 mongodb-1.0                | X             | X             | X             |               
 mongo-1.6                  | X             | X             | X             |               
 mongo-1.5                  | X             | X             |               |               

 PHP Driver  | PHP 5.3 | PHP 5.4 | PHP 5.5 | PHP 5.6 | PHP 7.0 | HHVM 3.9 
-------------|---------|---------|---------|---------|---------|----------
 mongodb-1.1 |         | X       | X       | X       | X       | X        
 mongodb-1.0 |         | X       | X       | X       |         | X        
 mongo-1.6   | X       | X       | X       | X       |         |          
 mongo-1.5   | X       | X       | X       | X       |         |          

From a code point of view, the new extension has a greater focus on low-level operations for communication with Mongodb, so much so that it is recommended to use it in conjunction with the Mongodb Library to have an interface similar to the old driver.

I will have to migrate my application to this new driver?

In your case, it depends on the version of PHP and Mongodb you are using. The latest version of the old driver supports up to Mongodb 3.0 and PHP 5.6. Just remove the new driver and install the old version. You can do that using the PECL.

If you want to use the newer version of Mongodb or PHP 7, then you need to change your code to use library most recent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.