-
Notifications
You must be signed in to change notification settings - Fork 8
Home
PHP CouchDB is a lightweight library wrapping Guzzle to make it easy to work with documents in CouchDB. Requirements: PHP7+, CouchDB 2.0 or later (but quite a lot of things will work with CouchDB 1.6, we're just not supporting it)
Here on the wiki you will find a selection of examples and other resources. There is also API documentation; this doesn't currently have a permanent home so you should generate this yourself using composer phpcs
in the top-level directory. This places the API docs in the docs/
folder.
Install the project with Composer:
composer require ibm-watson-data-lab/php-couchdb
A very simple tour of things you can do with this library:
<?php
require "vendor/autoload.php";
// connect to CouchDB (does make a call to check we can connect)
$server = new \PHPCouchDB\Server(["url" => "http://localhost:5984"]);
// get a list of databases; each one is a \PHPCouchDB\Database object
$databases = $server->getAllDbs();
// work with the "test" database (also a \PHPCouchDB\Database object)
$test_db = $server->useDb(["name" => "test", "create_if_not_exists" => true]);
// add a document - you may specify the "id" here if you like
$doc = $test_db->create(["name" => "Alice", "interests" => ["eating", "wondering"]]);
// inspect the document
print_r($doc);
// update the document - a NEW document is returned by this operation, showing the server representation of the document
$doc->friends[] = "Cheshire Cat";
$updated_doc = $doc->update();
// done? Delete the doc
$updated_doc->delete();
More in the Examples section.
If you have questions or feature requests, or notice a bug, please file an issue on the GitHub project https://github.com/ibm-watson-data-lab/php-couchdb/issues. We're always happy to hear from you!