icicleio / postgres
Icicle 的异步 PostgreSQL 客户端。
dev-master
2016-05-09 18:08 UTC
Requires
- icicleio/icicle: dev-master
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-09-14 02:28:00 UTC
README
这个库是 Icicle 的一个组件,提供了一个 PostgreSQL 的异步客户端。与其他 Icicle 组件一样,这个库使用由 协程、可等待对象 和 生成器 构建的工具,使得编写异步代码更像编写同步代码。
文档和支持
要求
- PHP 5.5+ 用于 v0.1.x 分支
- PHP 7 用于 v1.0 (v1.x 分支和 master) 支持生成器委托和返回表达式
安装
推荐使用 Composer 包管理器进行安装。(有关安装和使用 Composer 的信息,请参阅 Composer 安装指南。)
运行以下命令以在项目中使用此库
composer require icicleio/postgres
您还可以手动编辑 composer.json
以将此库添加为项目需求。
// composer.json { "require": { "icicleio/postgres": "^0.1" } }
示例
请注意,此示例仅适用于 PHP 7+ 的 v1.x(master)分支。
#!/usr/bin/env php <?php require __DIR__ . '/vendor/autoload.php'; use Icicle\Postgres; Icicle\execute(function () { /** @var \Icicle\Postgres\Connection $connection */ $connection = yield from Postgres\connect('host=localhost user=postgres dbname=test'); /** @var \Icicle\Postgres\Statement $statement */ $statement = yield from $connection->prepare('SELECT * FROM test WHERE id=$1'); /** @var \Icicle\Postgres\TupleResult $result */ $result = yield from $statement->execute(1337); $iterator = $result->getIterator(); while (yield from $iterator->isValid()) { $row = $iterator->getCurrent(); // $row is an array (map) of column values. e.g.: $row['column_name'] } });