CouchDB NoSQL database access in PHP

4.0.2 2023-09-12 01:03 UTC


Latest Stable VersionLatest Unstable VersionBuild StatusDocumentation StatusScrutinizer Code QualitycodecovLicense

🔥For the complete documentation, visit 🔥

Table of content


PHP On Couch provides an easy way to work with your CouchDB documents with PHP.

Supports PHP 5.6 and higher 🚀

Recent changes

For the complete change list, head over here

Installation and testing

Install the library using composer : composer require php-on-couch/php-on-couch. You can find more detailed informations about installation here.

To test the the application, see this topic.

Components and documentation

For the full API document, please visite this link


For full examples, refer to the database example or the document example.

At first, you need to import the main components through their namespace. If you use composer, I suggest you to use their autoload wich is easy to setup. Otherwise, you can use your own autoload function or a basic require with some namespace escaping.

use  PHPOnCouch\CouchClient; //The CouchDB client object

Here's an example for basic operations

// Set a new connector to the CouchDB server
$client = new CouchClient('', 'my_database');

// document fetching by ID
$doc = $client->getDoc('some_doc_id');
// updating document
$doc->newproperty = array("hello !", "world");
try {
} catch (Exception $e) {
    echo "Document storage failed : " . $e->getMessage() . "<BR>\n";

Here's a quick example of how to fetch a view

// view fetching, using the view option limit
try {
    $view = $client->limit(100)->getView('orders', 'by-date');
} catch (Exception $e) {
    echo "something weird happened: " . $e->getMessage() . "<BR>\n";

Finally, how to use the CouchDocument class.

//using couch_document class :
$doc = new CouchDocument($client);
$doc->set(array('_id' => 'JohnSmith', 'name' => 'Smith', 'firstname' => 'John')); //create a document and store it in the database
echo $doc->name; // should echo "Smith"
$doc->name = "Brown"; // set document property "name" to "Brown" and store the updated document in the database



Feel free to make any contributions. All contributions must follow the code style and must also comes with valid and complete tests.

Help is really appreciated to complete add more tests.


Gitter chat

Don't hesitate to submit feedback, bugs and feature requests ! Our contact address is