Swoole Coroutine Postgres

Swoole\Coroutine\Postgres

Coroutine PHP PostgreSQL client.

Pre-requirement

  • libpq is required.
  • ext-postgresql is requried.

Install ext-postgresql

git clone [email protected]:swoole/ext-postgresql.git
phpize
./configure
make && make install

Then add extension=swoole_postgresql.so to your php.ini file to enable the Swoole Postgres extension.

How to use Swoole Postgres Client

The methods available are same as the original PHP PostgreSQL client.

Example:

<?php
go(function () {
    $pg = new Swoole\Coroutine\PostgreSQL();
    $conn  = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password=");
    $result = $pg -> query($conn, 'SELECT * FROM test;');
    $arr = $pg -> fetchAll($result);
    var_dump($arr);
});