Skip to content

KushalRaj/phpcouch

Repository files navigation

Latest Stable VersionLatest Unstable VersionBuild StatusDocumentation StatusScrutinizer Code QualitycodecovLicense

🔥For the complete documentation, visit http://php-on-couch.readthedocs.io 🔥

Table of content

Introduction

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

Example

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('http://my.couch.server.com:5984', 'my_database');

// document fetching by ID
$doc = $client->getDoc('some_doc_id');
// updating document
$doc->newproperty = array("hello !", "world");
try {
    $client->storeDoc($doc);
} 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

Community

Contributions

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.

Feedback

Gitter chat

Don't hesitate to submit feedback, bugs and feature requests ! Our contact address is phponcouch@gmail.com

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published