In PHP development, Mongo extension is used to link MongoDB resources for adding, deleting, modifying and checking operations.
When selecting the Mongo extension, there are two available:
First: pecl.php.net/package/mon…
Second: pecl.php.net/package/mon…
On the second screen, the official message: This package has been superseded, but is still maintained for bugs and security fixes.
The package has been replaced, but the bugs and security patches remain, until when.
The obvious alternative is the first one.
So what’s the difference between these two extensions?
Different link methods
// The extension of the first installation is mongo$mongoUrl = "Mongo: / / 127.0.0.1:27017 / user_info";
$mongoClient = new MongoClient($mongoUrl);
$mongoDB = $mongoClient->user_info;
$collections = $mongoDB->listCollections();
foreach ($collections as $collection) {
var_dump($collection);
}
Copy the code
// Install the composer using composer (see the end of the installation method) // Composer require mongodb/mongodb require'vendor/autoload.php'; //include Composer's autoloader $mongoUrl = "mongo: / / 127.0.0.1:27017 / user_info"; $mongoClient = new MongoDB\Client($mongoUrl); $mongoDB = $mongoClient->user_info; $collections = $mongoDB->listCollections(); foreach ($collections as $collection) { var_dump($collection); }Copy the code
Different release times
Mongo 1.6.14(latest version) 2016-04-26 release.
Mongodb 1.2.6(latest version) was released on March 07 2017.
As for when Mongo will stop maintenance, there is no specific answer.
Other different
May be in the specific use of the process, to distinguish.
It is said that the classes and interfaces provided by the two extensions are completely different.
Go explore
advice
The MONgo extension is recommended for PHP versions 5.x.
The MONGODB extension is recommended for PHP version 7.
Of course, php5.x can also use mongodb extensions.
However, PHP7 cannot use the Mongo extension.
PHP can install both versions at the same time, as shown below:
The PHP manual:
Secure.php.net/manual/zh/b…
Secure.php.net/manual/zh/s…
Install the composer
/ / Linux servercd ~
curl -sS | https://getcomposer.org/installer PHP / / move to bin directory mv composer. The phar/usr /local/bin/composer -v // Create a composer. Json file {"require": {}}Copy the code
Thanks ~