PHPackages                             maxgaussdev/ccouchconnect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. maxgaussdev/ccouchconnect

ActiveLibrary

maxgaussdev/ccouchconnect
=========================

A shell cURL wrapper for CouchDB on PHP

06PHP

Since Apr 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/MaxGaussDev/CCouchConnect)[ Packagist](https://packagist.org/packages/maxgaussdev/ccouchconnect)[ RSS](/packages/maxgaussdev-ccouchconnect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

CCouchConnect
=============

[](#ccouchconnect)

This is a simple PHP CouchDB cURL Wrapper, for basic CRUD commands in CouchDB.

\#Importing

Using composer:

```
composer require maxgaussdev/ccouchconnect

```

To import the class all you need to do is include the CCouchConnect.php file and use the namespace:

```
include('CCouchConnect.php');

use CCouch\Database\CCouchConnect as Database;

```

\#Setting up the database

The constructor will support method overload, so basically there are three ways to create a Database Object:

```
$db = new Database('database', 'server');
$db = new Database('database', 'server', 5984);
$db = new Database('database', 'server', 5984, 'username', 'password');

```

By default the port will be set to the usual 5984 on CouchDB.

It is recommended that you use already existing database, but in case you need to create one with PHP, there is a createDatabase() method, that can be used in several ways:

```
// declare a new database that does not exist on the server
$db = new Database('database', 'server');

// we use createDatabase() method to create it
if(!$db->createDatabase->error){
	// success
}else{
	// fail
}

// this can also be set using empty constructor and usual setters
$db = new Database();

$db->setDatabase('dbname');
$db->setServer('localhost');

if(!$db->createDatabase->error){
	// success
}else{
	// fail
}

```

If not set in advance, the port will be defined by the default 5984.

\#How to use

Public methods for database queries will return stdObjects as result, use print\_r() for details if needed.

There are a couple of methods that will allow you to do the basic CRUD for objects. The return values by default will be php's stdObjects.

The Database info:

```
$result = $db->dbInfo();

```

\#Creating the document:

```
$document = array(
    "name" => "foo",
    "occupation" => "bar"
);
$result = $db->addNew($document);

```

This will return an std object with createdAt and updatedAt parameters by default (using Datetime), like this:

```
stdClass Object
(
    [_id] => efdf1c6dde49b78bf9834424131037f5
    [_rev] => 1-4fb5af102470b0304292ec418e0cab09
    [name] => foo
    [occupation] => bar
    [createdAt] => stdClass Object
        (
            [date] => 2016-04-08 11:41:06.000000
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

    [updatedAt] => stdClass Object
        (
            [date] => 2016-04-08 11:41:06.000000
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

)

```

\#Getting the document:

There are a couple of methods to retrieve a document from CouchDB.

```

// returns document object by _id
$result = $db->findById('efdf1c6dde49b78bf9834424131037f5');

// returns an array of document objects filtered by array of keys and their values
$result = $db->findBy(array("key" => "value"));

// returns a document object filtered by array of keys and their values
$result = $db->findOneBy(array("key" => "value"));

// example with our object above:
$result = $db->findOneBy(array("name" => "foo", "occupation" => "bar"));

$result = $db->findAll();
// returns an array of all document objects

```

findBy() methods create a view in the database (by default the design document is \_design/ccouch\_views), with the md5 hash for the view name for each search input.

In case you don't want the search data to be cached in design document there are two following methods:

```
$result = $db->findByNoCache(array("key" => "value"));
$result = $db->findOneByNoCache(array("key" => "value"));

```

Both methods will return the data using temporary views.

In case you wish to search for documents with a keyword value in any non-specified parameter, there is a simple search method implemented:

```
$result = $db->search('keyword');

```

\#Find documents with limit and offset:

Limit and offset can be used in the following way and are optional arguments:

```
$result = $db->findAll($limit, $offset);
$result = $db->findByNoCache(array("key" => "value"),$limit, $offset);
$result = $db->findBy(array("key" => "value"),$limit, $offset);

```

\#Updating and Deleting the document:

Updating a document is simple, you just pass an object as an argument to save() method:

```
// some document from the database
$document = $db->findById('efdf1c6dde49b78bf9834424131037f5');
$document->name = "foo foo";

$result = $db->save($document);

```

Deleting the document:

```
// some document from the database
$document = $db->findById('efdf1c6dde49b78bf9834424131037f5');

$result = $db->delete($document);

```

Although it is not advised, you can also Purge the document. Typical CouchDb purge rules apply:

```
// some document from the database
$document = $db->findById('efdf1c6dde49b78bf9834424131037f5');

$result = $db->purge($document);

```

\#Bulk methods:

There are two bulk methods currently. Adding and Deleting multiple documents in a single request:

```
// some documents
$documentsArray = array($document1, $document2, $document3,...);

// add multiple new documents
$result = $db->saveBulk($documentsArray);

// delete multiple documents
$result = $db->deleteBulk($documentsArray);

```

Both methods will accept array of document objects as argument. Return result will be an array of objects with statuses.

\#Additional methods:

```
// get document ids (findAll() withoud document details)
$result = $db->listDocuments();

// get ids of changed documents
$result = $db->listChanges();

// get list of all databases
$result = $db->listDatabases();

// delete database
$result = $db->deleteDatabase();

```

\#Future Releases:

Here is the list of plans for future releases:

- support for custom views manipulation
- attachments support
- cache cleaning
- documentation update

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bbb753bcffac9a4a44a1745f9eee7c81f29203f2378de3e308673a3cf5a1a21b?d=identicon)[maxgaussdev](/maintainers/maxgaussdev)

---

Top Contributors

[![MaxGaussDev](https://avatars.githubusercontent.com/u/6883797?v=4)](https://github.com/MaxGaussDev "MaxGaussDev (6 commits)")

### Embed Badge

![Health badge](/badges/maxgaussdev-ccouchconnect/health.svg)

```
[![Health](https://phpackages.com/badges/maxgaussdev-ccouchconnect/health.svg)](https://phpackages.com/packages/maxgaussdev-ccouchconnect)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
