redaigbaria/cloudant

此包的最新版本(dev-master)没有可用的许可信息。

CouchDB NoSQL数据库的PHP访问

dev-master 2016-11-07 11:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:47:29 UTC


README

PHP On Couch 尝试提供一种简单的方式来使用 CouchDB 文档PHP。一些代码示例

<?PHP
require_once 'couch.php';
require_once 'couchClient.php';
require_once 'couchDocument.php';

// set a new connector to the CouchDB server
$client = new couchClient ('http://my.couch.server.com:5984','my_database');

// document fetching by ID
$doc = $client->getDoc('some_doc_id');
// updating document
$doc->newproperty = array("hello !","world");
try {
   $client->storeDoc($doc);
} catch (Exception $e) {
   echo "Document storage failed : ".$e->getMessage()."<BR>\n";
}

// view fetching, using the view option limit
try {
   $view = $client->limit(100)->getView('orders','by-date');
} catch (Exception $e) {
   echo "something weird happened: ".$e->getMessage()."<BR>\n";
}

//using couch_document class :
$doc = new couchDocument($client);
$doc->set( array('_id'=>'JohnSmith','name'=>'Smith','firstname'=>'John') ); //create a document and store it in the database
echo $doc->name ; // should echo "Smith"
$doc->name = "Brown"; // set document property "name" to "Brown" and store the updated document in the database

组件

此库有四个主要类和一个自定义的 异常 类。

couch类

这是三个类中最基础的,负责PHP与CouchDB服务器之间的底层对话。通常不需要直接使用它。

couchClient类

此类映射了应用程序可以在CouchDB服务器上执行的所有操作。文档分为三个主要主题

数据库相关

列出数据库,创建和删除数据库,获取数据库信息,测试数据库是否存在,获取uuid,获取数据库变更

文档相关

获取和存储文档,复制文档,存储和删除文档附件,获取所有文档

视图相关

带有查询选项(键,startkey,endkey,limit,stale等)调用视图

couchDocument类

简化文档操作,couchDocument类使用PHP魔术获取器和设置器。

couchReplicator类

一个专门用于管理跨不同CouchDB数据库实例的复制的类。

couchAdmin类

一个用于管理用户和数据库/用户关联的类

快速入门指南

  1. 将couch.php,couchClient.php和couchDocument.php复制到您的磁盘上的某个位置

  2. 每当您需要访问CouchDB服务器时,请包含这些文件

     <?PHP
     require_once "couch.php";
     require_once "couchClient.php";
     require_once "couchDocument.php";
    

如果您需要使用复制功能,也请包含couchReplicator定义

    require_once "couchReplicator.php";
  1. 创建一个客户端对象。您必须告诉它CouchDB服务器的 数据源名称(dsn),以及您要工作的数据库的名称。dsn是CouchDB服务器的URL,例如 https://:5984

     $client = new couchClient($couchdb_server_dsn, $couchdb_database_name);
    
  2. 开始使用!

     try {
         $client->createDatabase();
     } catch (Exception $e) {
         echo "Unable to create database : ".$e->getMessage();
     }
     
     $doc = new couchDocument($client);
     $doc->set( array('_id'=>'some_doc_id', 'type'=>'story','title'=>"First story") );
     
     $view = $client->limit(10)->descending(TRUE)->getView('some_design_doc','viewname');
    

反馈

不要犹豫,提交反馈、错误报告和功能请求!我的联系地址是 mickael dot bailly at free dot fr

资源

数据库API

文档API

视图API

couchDocument API

couchReplicator API

couchAdmin API