public function __construct($db_name, Document $document)
 {
     $url = '/' . $db_name . '/' . $document->getId();
     $method = 'PUT';
     $data = $document->getJson();
     parent::__construct($url, $method, $data);
 }
 public function __construct(CouchDBResponse $response)
 {
     if ($response->isOk()) {
         $this->document_list = array();
         $data = $response->getBody(true);
         $this->count = $data['total_rows'];
         $this->offset = $data['offset'];
         if (isset($data['rows'])) {
             foreach ($data['rows'] as $documentData) {
                 $doc_id = $documentData['id'];
                 $doc_rev = $documentData['value']['rev'];
                 $data = isset($documentData['doc']) ? $documentData['doc'] : null;
                 unset($data['_id']);
                 unset($data['_rev']);
                 $_tmp = new Document();
                 $_tmp->parseData($doc_id, $doc_rev, $data);
                 $this->document_list[] = $_tmp;
             }
         }
     }
 }
$connector = new couch\CouchDB();
echo "Test Connection";
$response_test = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__TEST));
dump($response_test);
echo "Create a new Database";
$response_create_db = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__CREATE_DATABASE, 'test_db'));
dump($response_create_db);
echo "Delete a database";
$response_delete_db = $connector->sendCommand(new couch\command\DeleteDatabase('db_name'));
dump($response_delete_db);
echo "List all databases";
$response_list_dbs = $connector->sendCommand(couch\CouchDB::createCommand(couch\CouchDB::CMD__LIST_ALL_DBS));
dump($response_list_dbs);
echo "Try to fetch document and create/update it";
$response_get_document = $connector->sendCommand(new couch\command\GetDocument('test_db', "setup"));
$document = $response_get_document->isOk() ? new couch\data\Document($response_get_document) : couch\data\Document::create('setup');
// change documents data
$document->set('name', 'max-muster');
$document->set('geburtsjahr', 1525);
$document->set('ort', 'musterstadt');
$document->set('ORT', 'MUSTERSTADT');
// update or create document
try {
    $response_update_or_create_document = $connector->sendCommand(new couch\command\UpdateDocument("test_db", $document));
    dump($response_update_or_create_document);
} catch (Exception $exc) {
    echo '<div class="error">' . $exc->getMessage() . '</div>';
}
echo "List documents in database";
$response_list_documents_in_db = $connector->sendCommand(new couch\command\ListDocuments('test_db'));
dump($response_list_documents_in_db);
<?php

define('LOCAL_CLASS_PATH', realpath('./') . '/');
set_include_path(get_include_path() . PATH_SEPARATOR . LOCAL_CLASS_PATH);
spl_autoload_register();
use net\servicehome\connector\couchdb as couch;
$connector = new couch\CouchDB();
// CREATE DB
////////////////////////
$db_name = "test_db";
$response = $connector->sendCommand(new couch\command\CreateDatabase($db_name));
var_dump($response);
// CREATE sample entries
////////////////////////
$document = couch\data\Document::create("entry_a");
$document->set("Art", "Obst");
$document->set("Name", "Orange");
$document->set("Preis", 1.5);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_b");
$document->resetRevision();
$document->set("Art", "Obst");
$document->set("Name", "Apfel");
$document->set("Preis", 1.2);
$response = $connector->sendCommand(couch\command\CreateDocument::initWithDoc($db_name, $document));
var_dump($response);
$document->setId("entry_c");
$document->resetRevision();
$document->set("Art", "Obst");
$document->set("Name", "Birne");