HeadCouch
Version 1.0.1
CouchDB PHP client
Build | Stable | License |
---|---|---|
require __DIR__ . '/vendor/autoload.php';
$transport = HeadCouchCurl::newInstance('127.0.0.1', 5984)
->setUsername('my_username')
->setPassword('my_password');
$transport = HeadCouchSocket::newInstance('127.0.0.1', 5984)
->setUsername('my_username')
->setPassword('my_password');
$transport = HeadCouchFile::newInstance('127.0.0.1', 5984)
->setUsername('my_username')
->setPassword('my_password');
$server = HeadCouchServer::newInstance($transport);
// Accessing the root of a CouchDB instance
$response = $server->ping();
// Requests a Universally Unique Identifier from the CouchDB instance
$response = $server->uuid();
// Returns a list of all the databases
$response = $server->allDbs();
// List of running tasks
$response = $server->activeTasks();
// Returns a list of all database events in the CouchDB instance
$response = $server->dbUpdates();
// Gets the CouchDB log
$response = $server->log();
// Restarts the CouchDB instance
$response = $server->restart();
// Returns the statistics for the running server
$response = $server->stats();
try {
$database = HeadCouchDatabase::newInstance($transport, 'db_name');
} catch (HeadCouchException $e) {
echo $e->getMessage();
}
// Create database
$response = $database->create();
// Delete database
$response = $database->delete();
// Gets information about the specified database
$response = $database->get();
// Returns the HTTP Headers about the specified database
$response = $database->head();
// Creates a new document in the specified database
$response = $database->post(array(
'key1' => 'val1',
'key2' => 'val2'
));
try {
$document = HeadCouchDocument::newInstance($transport, 'db_name', 'doc_name');
} catch (HeadCouchException $e) {
echo $e->getMessage();
}
// Creates a new document
$response = $document->create(array(
'key1' => 'val1',
'key2' => 'val2'
));
// Deletes the specified document from the database
$response = $document->delete();
// Returns document
$response = $document->get();
// Returns document's revision token
$response = $document->getRevision();
// Returns the HTTP Headers about the specified document
$response = $document->head();
$result = $response->toArray();
// print_r($result);
$result = $response->toObject();
// get_object_vars($result);
$result = $response->toString();
// echo $result;