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 .