<?php
/*
Copyright (C) 2011-2012 Codernity.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__) . '/codernitydb.php';
$config = array(
'username' => 'admin',
'password' => 'password'
);
$db = new Codernitydb($config);
$doc = array(
'key1' => 'Value 1',
'key2' => 'Value 2'
);
$insert = $db->insert($doc);
echo "INSERT:\n----------------------------------------------------\n";
var_dump($insert);
if ($insert->status != 200) {
echo $insert->details['error'];
exit;
}
$docId = $insert->doc['_id'];
$revId = $insert->doc['_rev'];
$get = $db->get($docId);
echo "GET:\n----------------------------------------------------\n";
print_r($get);
if ($get->status != 200) {
echo $get->details['error'];
exit;
}
$doc = $get->doc;
$doc['key3'] = 'Value 3';
$update = $db->update($doc);
if ($update->status != 200) {
echo $update->details['error'];
exit;
}
echo "UPDATE:\n----------------------------------------------------\n";
print_r($update);
$docId = $update->doc['_id'];
$revId = $update->doc['_rev'];
$get = $db->get($docId);
echo "GET:\n----------------------------------------------------\n";
print_r($get);
$delete = $db->delete($docId, $revId);
if ($delete !== true) {
echo $delete->details['error'];
exit;
}
echo "DELETE:\n----------------------------------------------------\n";
var_dump($delete);