#!/usr/bin/php -q #### Creating database http://ben:ben1@localhost:5984/example: $result = $client->createDatabase(); Database successfully created. CouchDB sent the response :stdClass Object ( [ok] => 1 ) #### Storing a document Storing $doc : $client->storeDoc($doc) The document is stored. CouchDB response body: stdClass Object ( [ok] => 1 [id] => some_doc [rev] => 1-75c8ea2ebdb0edfa8ada19a22138b1f3 ) #### Storing a document without _id property Storing $doc : $client->storeDoc($doc) The document is stored. CouchDB response body: stdClass Object ( [ok] => 1 [id] => ba0bbffcc0c9e5200f9bfdd91900cee3 [rev] => 1-5596032f60af3f357e1c060c55909fde ) CouchDB created the unique identifier ba0bbffcc0c9e5200f9bfdd91900cee3 for this document ==== using previous $doc object to update it Adding revison and id properties to the object : $doc->_id = $response->id; $doc->_rev = $response->rev; Making a change : $doc->tags[] = "updated"; ==== storing document Storing $doc : $client->storeDoc($doc) The document is stored. CouchDB response body: stdClass Object ( [ok] => 1 [id] => ba0bbffcc0c9e5200f9bfdd91900cee3 [rev] => 2-1930255321c3f18abf4341a67f13e015 ) The revision property changed : 2-1930255321c3f18abf4341a67f13e015 #### Storing doc without updating _rev property (this should gice an error) The document update failed: Conflict - Document update conflict. (PUT /example/ba0bbffcc0c9e5200f9bfdd91900cee3 []) (errcode=409) #### Getting document: some_doc getting doc : $doc = $client->getDoc('some_doc') Document retrieved: stdClass Object ( [_id] => some_doc [_rev] => 1-75c8ea2ebdb0edfa8ada19a22138b1f3 [title] => Important documentation [tags] => Array ( [0] => documentation [1] => secret ) ) #### Deleting document "some_doc" delete using previous $doc object : $client->deleteDoc($doc) Doc deleted, CouchDB response body: stdClass Object ( [ok] => 1 [id] => some_doc [rev] => 2-e835155824f699c08bfe888d557a45f3 )