1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-30 04:29:12 +01:00
Go to file
Aaron Piotrowski 492d059a52 Namespace typo
2016-10-05 10:00:16 -05:00
example Fix nofication listening; add notify() method to Executor 2016-09-21 00:18:24 -05:00
lib Namespace typo 2016-10-05 10:00:16 -05:00
test Test and formatting updates 2016-09-20 00:47:16 -05:00
.gitattributes Initial commit 2016-09-14 09:27:39 -05:00
.gitignore Initial commit 2016-09-14 09:27:39 -05:00
.travis.yml Fix travis build 2016-09-14 09:47:43 -05:00
composer.json Initial commit 2016-09-14 09:27:39 -05:00
LICENSE Initial commit 2016-09-14 09:27:39 -05:00
phpdoc.dist.xml Initial commit 2016-09-14 09:27:39 -05:00
phpunit.xml.dist Fix whitelist 2016-09-14 23:40:12 -05:00
README.md Initial commit 2016-09-14 09:27:39 -05:00

PostgreSQL Client for Amp

This library is a component for Amp that provides an asynchronous client for PostgreSQL.

Build Status Coverage Status Semantic Version MIT License @amphp on Twitter

Requirements
  • PHP 7
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.1"
    }
}

Example

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Amp\Postgres;

Amp\execute(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->next()) {
        $row = $result->getCurrent();
        // $row is an array (map) of column values. e.g.: $row['column_name']
    }
});