Reputation: 4672
What is the difference between the mongo-php-library and the MongoDB driver? How are they different in terms of performance and features? What are the pros and cons?
We are currently using the "mongo-php-library" in production like this:
$connection = (new MongoDB\Client("mongodb://user:password@mongo:27017"));
$client = $connection->selectDatabase("the_database");
$collection_users = $client->selectCollection('users');
Are there any up or downsides connecting to a database like this?
Upvotes: 3
Views: 2102
Reputation: 14469
mongo-php-library (written in PHP) is a high-level abstraction around the lower-level MongoDB PHP driver (mongodb extension). MongoDB driver mongodb is written in C and provides only a minimal API for core driver functionality: commands, queries, writes, connection management, and BSON serialization. Therefore PHP developers will need mongo-php-library to provide the easy-to-use higher level APIs, such as query builders, individual command helper methods, and GridFS.
mongo-php-library is officially supported by MongoDB. There is no issue or concern to its performance and features as it's the only choice, unless you decide to develop yourself a customized/optimized library, which may ends up in reinventing the same wheel.
Previously the legacy MongoDB PHP driver provides instead the high level APIs, but MongoDB decide to supersede it with current mongodb extension, so the legacy driver only supports up to PHP 5.6 and MongoDB 3.0. The reason for this is unknown, but we guess MongoDB wants to keep the MongoDB PHP driver at low level and develops a PHP library on top of this to facilitate their support for PHP 7 and subsequent PHP upgrades.
Upvotes: 7