mirror of
https://github.com/danog/postgres.git
synced 2024-11-30 04:29:12 +01:00
7a8358ee69
Temp fix for travis issues. |
||
---|---|---|
examples | ||
lib | ||
test | ||
travis | ||
.gitattributes | ||
.gitignore | ||
.php_cs.dist | ||
.travis.yml | ||
composer.json | ||
LICENSE | ||
Makefile | ||
phpdoc.dist.xml | ||
phpunit.xml.dist | ||
README.md |
PostgreSQL Client for Amp
This library is a component for Amp that provides an asynchronous client for PostgreSQL.
Requirements
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 amphp/postgres
You can also manually edit composer.json
to add this library as a project requirement.
// composer.json
{
"require": {
"amphp/postgres": "^0.2"
}
}
Example
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Amp\Postgres;
Amp\Loop::run(function () {
/** @var \Amp\Postgres\Connection $connection */
$connection = yield Postgres\connect('host=localhost user=postgres dbname=test');
/** @var \Amp\Postgres\Statement $statement */
$statement = yield $connection->prepare('SELECT * FROM test WHERE id=$1');
/** @var \Amp\Postgres\TupleResult $result */
$result = yield $statement->execute(1337);
while (yield $result->advance()) {
$row = $result->getCurrent();
// $row is an array (map) of column values. e.g.: $row['column_name']
}
});