PHP code example of f2h2h1 / couchdb-client
1. Go to this page and download the library: Download f2h2h1/couchdb-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
f2h2h1 / couchdb-client example snippets
use F2h2h1\CouchDB\SimpleClinet;
niqid(microtime(true), true)), 0, mt_rand(3, 6));
$config = [
'address' => 'http://127.0.0.1:5984',
'user' => 'admin',
'password' => 'password',
'dbname' => $dbname,
];
$client = new SimpleClinet($config);
$client->deleteDatabase();
$client->createDatabase();
echo 'create database success' . PHP_EOL;
$data = ['name' => 'tony', 'age' => 23];
list($id, $rev) = $client->postDocument($data);
var_dump($id, $rev);
$docs = $client->findDocument($id);
var_dump($docs);
$data['age'] = 24;
list($id, $rev) = $client->putDocument($data, $id, $rev);
var_dump($id, $rev);
$docs = $client->findDocument($id);
var_dump($docs);
$client->deleteDocument($id, $rev);
echo 'delete document success' . PHP_EOL;
$client->deleteDatabase();
echo 'delete database success' . PHP_EOL;
shell
composer exec -v phpunit tests/CouchDBClientTest.php