Class Couch

Description

CouchDb PHP Library

This library allows you to talk to a CouchDb server from within PHP. It saves you writing access functions to CouchDb's REST API. The primary goal of this library is ease of use. To achieve this, trade-offs had to be taken. They include speed optimiziation and cleaner code. A minor but also important goal was to allow this library to be used from PHP versions 4 to 6. Libraries with less code can be written for PHP 5 and 6 and they are planned already, but this is what is here now and it can be used by everyone.

A note on object oriented programming (OOP): This library makes use of PHP's OOP syntax but it does not neccessarily adhere to more advanced OOP design principles. The purpose of the two clases here is to encapsulate data and namespace functions. You can easily build a pure OOP Library on top of this library or from scratch.

The CouchDb PHP Library makes use of the PEAR package HTTP_Request which in turn uses the PEAR packge itself as well as Net_Socket and Net_URL.

To learn more about CouchDb, visit http://couchdb.com/

Usage Example:

 <?php
 include 'CouchDb/Couch.php';

 $couch = new Couch('localhost', 'test');
 if(!$couch->running()) {
 	die("The Couch is not running\n");
 }

 $doc = new CouchDocument;
 $doc->set('Name', 'Micha');
 $doc->set('Age', 24);
 $doc->set('Cool', 'true');
 $docid = $couch->save($doc);
 echo "Successfully inserted $docid\n";
 ?>

Enjoy!

  • copyright: Jan Lehnardt, 2006
  • version: 0.6.0
  • author: Jan Lehnardt <jan@php.net>

Located in /Couch.php (line 87)


	
			
Variable Summary
mixed $documents
string $host
mixed $php4
integer $port
mixed $silent
mixed $tables
string $table_doc_id
string $table_prefix
mixed $_curCol
mixed $_curDoc
mixed $_curRow
mixed $_curTag
mixed $_lastCount
mixed $_res
mixed $_tagCount
Method Summary
void Couch ([string $host = 'localhost'], [string $database = ''], [string $user = ''], [string $pass = ''], [integer $port = 8888], [array $request_options = array()])
void be_quiet ()
void be_verbose ()
bool db_create ()
void db_exists ()
bool delete (string $id)
bool exists (id $id)
mixed get (string $id, [array $options = array()])
array get_all (string $table, [array $options = array()])
string get_latest_error ()
bool running ()
mixed save (CouchDocument $doc, [string $id = ''], [string $rev = ''], [bool $escape = true])
void shout ()
void shush ()
void shut_up ()
void squeal ()
void table_add (mixed $name, [array $structure = false])
void table_delete (string $name)
void table_exists (mixed $name, array 1)
void table_update ( $name, [ $structure = false])
void throw_error ( $message,  $type)
void _parserCdata ( $parser,  $data)
void _parserEnd ( $parser,  $tag)
void _parseResult ( $xml)
void _parserStart ( $parser,  $tag,  $attributes)
void _sendRequest ( $url,  $method, [ $post_data = false])
void _xmlEscape ( $xml, [ $escape = true])
void _xmlUnEscape ( $xml)
Variables
mixed $documents = array() (line 112)
string $host = '' (line 94)

The host where CouchDb runs on

mixed $php4 = false (line 128)
integer $port = 0 (line 101)

The IP port that CouchDb listenes on

mixed $request_options = array() (line 103)
mixed $silent = false (line 129)
mixed $tables = false (line 131)
string $table_doc_id = '$tables' (line 126)

Document Id of the document that holds the computed tables

string $table_prefix = '$table_' (line 119)

Prefix for the fields of the document that holds the computed tables

mixed $_curCol = '' (line 108)
mixed $_curDoc = false (line 106)
mixed $_curRow = 0 (line 107)
mixed $_curTag = '' (line 109)
mixed $_lastCount = 0 (line 111)
mixed $_res = array() (line 105)
mixed $_tagCount = 0 (line 110)
Methods
Constructor Couch (line 144)

Constructor

void Couch ([string $host = 'localhost'], [string $database = ''], [string $user = ''], [string $pass = ''], [integer $port = 8888], [array $request_options = array()])
  • string $host: the host where CouchDb runs on
  • string $database: database name that is used with this instance of Couch
  • string $user: username (unused in 0.6.0)
  • string $pass: password (unused in 0.6.0)
  • integer $port: the port where CouchDb listens on
  • array $request_options: additional request options. See http://pear.php.net/package/HTTP_Request/docs/latest/apidoc/HTTP_Request/HTTP_Request.html#methodHTTP_Request
be_quiet (line 712)

Set the CouchDb Library to be quiet about errors. Use in production.

void be_quiet ()
be_verbose (line 679)

Set the CouchDb Library to display error messages. Only useful and needed during development. Don't use in production!

void be_verbose ()
db_create (line 178)

Creates the CouchDb database

bool db_create ()
db_exists (line 193)

Determines if the CouchDb database exists

void db_exists ()
delete (line 408)

Deletes a CouchDocument

  • return: success
bool delete (string $id)
  • string $id: CouchDocument id
exists (line 269)

Determines if a CouchDocument with a given ID exists

bool exists (id $id)
  • id $id: string docuemnt id
get (line 281)

Retrieves a single CouchDocument from the CouchDb database

  • return: CouchDocument or false on error
mixed get (string $id, [array $options = array()])
  • string $id: CouchDocument id
  • array $options: additional table request options. Not yet in use.
get_all (line 309)

Retrieves all documents from a table

  • return: of CouchDocuments or false on error
array get_all (string $table, [array $options = array()])
  • string $table: tablename
  • array $options: additional table request options, see http://www.couchdbwiki.com/index.php?title=HTTP_Computed_Tables_API#Querying_Options (Example: array('key' => 'foo', 'reverse' => 'true'))
get_latest_error (line 461)

Returns the lastest error message

  • return: error message
string get_latest_error ()
running (line 163)

Determines if CouchDb is running

bool running ()
save (line 357)

Saves a CouchDocument

  • return: saved CouchDocument id or false on error
mixed save (CouchDocument $doc, [string $id = ''], [string $rev = ''], [bool $escape = true])
  • CouchDocument $doc
  • string $id: CouchDocument id
  • string $rev: CouchDocument revision
  • bool $escape: xml escape data
shout (line 657)

Set the CouchDb Library to display error messages. Only useful and needed during development. Don't use in production!

void shout ()
shush (line 690)

Set the CouchDb Library to be quiet about errors. Use in production.

void shush ()
shut_up (line 701)

Set the CouchDb Library to be quiet about errors. Use in production.

void shut_up ()
squeal (line 668)

Set the CouchDb Library to display error messages. Only useful and needed during development. Don't use in production!

void squeal ()
table_add (line 207)

Adds a single or multiple computed tables to the CouchDb database

void table_add (mixed $name, [array $structure = false])
  • mixed $name: table name or table structure array
  • array $structure: table structure (if $name is a string)
table_delete (line 256)

Deletes a table form CouchDb's $tables CouchDocument

void table_delete (string $name)
  • string $name: tablename
table_exists (line 225)

Determines if a table already exists in the $tables CouchDocument

void table_exists (mixed $name, array 1)
  • array 1: table structure (if $name is a string)
  • mixed $name: table name or table structure array
table_update (line 235)

Updates a single or multiple table definitions

void table_update ( $name, [ $structure = false])
  • $name
  • $structure
throw_error (line 483)
void throw_error ( $message,  $type)
  • $message
  • $type
_parserCdata (line 555)
void _parserCdata ( $parser,  $data)
  • $parser
  • $data
_parserEnd (line 549)
void _parserEnd ( $parser,  $tag)
  • $parser
  • $tag
_parseResult (line 490)
void _parseResult ( $xml)
  • $xml
_parserStart (line 509)
void _parserStart ( $parser,  $tag,  $attributes)
  • $parser
  • $tag
  • $attributes
_sendRequest (line 424)
void _sendRequest ( $url,  $method, [ $post_data = false])
  • $url
  • $method
  • $post_data
_xmlEscape (line 608)
void _xmlEscape ( $xml, [ $escape = true])
  • $xml
  • $escape
_xmlUnEscape (line 631)
void _xmlUnEscape ( $xml)
  • $xml

Documentation generated on Sun, 19 Nov 2006 13:28:39 +0100 by phpDocumentor 1.3.1