Example #1
0
 *
 *    Licensed under the Apache License, Version 2.0 (the "License"); you may not
 *    use this file except in compliance with the License.  You may obtain a copy
 *    of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *    This library 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 License for the specific language governing permissions and
 *    limitations under the License.
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package Sample 
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2009 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
$document_id = 'target_documnet_id';
// Get an existing document
$document = $db->document($document_id);
echo '<pre>', print_r($document, true), '</pre>';
Example #2
0
 /**
  * @expectedException Exception
  */
 public function testDocumentGetWithNoDatabaseOption()
 {
     $couchdb = new CouchDB();
     $couchdb->document(1234);
 }
<?php

require $_SERVER['DOCUMENT_ROOT'] . '/application/system/Environment.php';
$key = filter_var($_GET['key'], FILTER_UNSAFE_RAW);
if (preg_match('/[\\w\\d]{32}/', $key)) {
    $options = array('database' => Configuration::kDatabaseName);
    $db = new CouchDB($options);
    $query_options = array('key' => $key);
    $result = $db->view('users/accountAuthorization', $query_options);
    if (count($result) > 0) {
        $authtoken = $result[0]['value']['key'];
        if ($authtoken == $key) {
            $user = new User();
            $db_user = $db->document($result[0]['value']['user']);
            $user->initWithArray($db_user);
            $user->isValid = true;
            $user->save();
            $db->delete($result[0]['value']['_id'], $result[0]['value']['_rev']);
        }
    }
    header('location: /');
}
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package Sample 
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2009 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
$document_id = 'target_documnet_id';
// Get an existing document
$document = $db->document($document_id);
echo '<h2>BEFORE</h2>';
echo '<pre>', print_r($document, true), '</pre>';
// Add a new value
$document['screenname'] = 'lipsum';
// As JSON
$json = json_encode($document);
$db->put($json, $document_id);
// OR As Array:
//$db->put($document, $document_id);
// Get the document again to show it changed
echo '<h2>AFTER</h2>';
echo '<pre>', print_r($db->document($document_id), true), '</pre>';