MongoDB extension not found in PHP 5.6

1

I'm developing an application in PHP 5.6 with Laravel 5.2 using MongoDB.

The problem came up 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 \MongoDB class does not exist even though it appears in phpinfo() version of the mongo drive 1.1.6.

What's going on?

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

Will I need to migrate my application to this new driver?

    
asked by anonymous 04.05.2016 / 20:00

1 answer

1

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

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

The driver you will be using depends on the version of PHP and the MongoDB that you are using.

See which ones to choose from the tables extracted from 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       |         |          

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

  

Will I need to migrate my application to this new driver?

In your case, it depends on the version of PHP and the MongoDB that 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 this using PECL .

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

    
31.07.2016 / 18:48