kgrhck/php-on-couch

CouchDB NoSQL数据库在PHP中的访问

4.0.0 2022-01-31 01:45 UTC

README

Latest Stable VersionLatest Unstable VersionBuild StatusDocumentation StatusScrutinizer Code QualitycodecovLicense

🔥完整的文档,请访问http://php-on-couch.readthedocs.io 🔥

目录

简介

PHP On Couch 提供了一种简单的方法,使用 CouchDB 文档PHP 进行交互。

支持PHP 5.6及以上版本 🚀

最近更改

完整的更改列表,请访问此处

安装和测试

使用composer安装库: composer require php-on-couch/php-on-couch。有关安装的更多信息,请参阅此处

要测试应用程序,请参阅本主题

组件和文档

完整的API文档,请访问此链接

示例

有关完整示例,请参阅数据库示例文档示例

首先,您需要通过它们的命名空间导入主要组件。如果您使用composer,建议您使用其自动加载,这很容易设置。否则,您可以使用自己的自动加载函数或基本require与一些命名空间转义。

use  PHPOnCouch\CouchClient; //The CouchDB client object

以下是一个基本操作的示例

// 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";
}

最后,如何使用CouchDocument类。

//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

社区

贡献

请随时做出任何贡献。所有贡献都必须遵循 代码风格,并且还必须附带有效和完整的测试。

真的非常感谢帮助完成更多测试。

反馈

Gitter chat

不要犹豫,提交反馈、错误报告和功能请求!我们的联系方式是phponcouch@gmail.com