PHP MongoDB Driver

For the official MongoDB PHP reference, see:

Access MongoDB from PHP

To access MongoDB from PHP you need:

  • The MongoDB server running. The server is the “mongod” file, not the “mongo” client (note the “d” at the end).
  • The MongoDB PHP driver installed.

Drivers

The currently maintained driver is the mongodb extension available from PECL. This driver can be used stand-alone, although it is very bare-bones. You should consider using the driver with the complimentary PHP library, which implements a more full-featured API on top of the bare-bones driver.

For further information on the architecture, please refer to this blog post.

There is also an older legacy driver called mongo. New projects should use the mongodb extension with the PHP library. The links below point to the documentation for the new mongodb extension.

Compatibility

MongoDB Compatibility

The following compatibility table specifies the recommended version(s) of the MongoDB PHP driver for use with a specific version of MongoDB.

The first column lists the driver version(s).

In the table below, mongodb and mongo refer to the new and legacy MongoDB PHP driver, respectively. PHPLIB refers to the userland library.

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

For additional driver versions, see PHP Driver MongoDB Compatibility Reference.

The driver does not support older versions of MongoDB.

Language Compatibility

The following compatibility table specifies the recommended version(s) of the MongoDB PHP driver for use with a specific version of PHP.

The first column lists the driver version(s).

In the table below, mongodb and mongo refer to the new and legacy MongoDB PHP driver, respectively.

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

For additional driver versions, see PHP Driver Language Compatibility Reference.

See Also