icicleio / postgres
Asynchronous PostgreSQL client for Icicle.
Requires
- icicleio/icicle: dev-master
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-11-14 02:51:59 UTC
README
This library is a component for Icicle that provides an asynchronous client for PostgreSQL. Like other Icicle components, this library uses Coroutines built from Awaitables and Generators to make writing asynchronous code more like writing synchronous code.
Documentation and Support
Requirements
- PHP 5.5+ for v0.1.x branch
- PHP 7 for v1.0 (v1.x branch and master) supporting generator delegation and return expressions
Installation
The recommended way to install is with the Composer package manager. (See the Composer installation guide for information on installing and using Composer.)
Run the following command to use this library in your project:
composer require icicleio/postgres
You can also manually edit composer.json
to add this library as a project requirement.
// composer.json { "require": { "icicleio/postgres": "^0.1" } }
Example
Note that this example uses the PHP 7+ only v1.x (master) branch.
#!/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'] } });