Skip to content

🐘 Coroutine-based client for PostgreSQL

Notifications You must be signed in to change notification settings

sergiotabanelli/ext-postgresql

 
 

Repository files navigation

Swoole Coroutine Postgres Client

ext-postgresql is the Swoole Postgres Client library can be used with in the coroutine context without blocking.

Pre-requirement

  • libpq is required
  • swoole version >= 4.4.0

Build & Installation

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

Enable swoole_postgresql in php.ini by adding the following line:

extension=swoole_postgresql.so

How to use the Postgres Client

<?php
Co\run(function () {
    $db = new Swoole\Coroutine\PostgreSQL();
    $db->connect("host=127.0.0.1 port=5432 dbname=test user=root password=password");
    $db->prepare('fortunes', 'SELECT id, message FROM Fortune');
    $res = $db->execute('fortunes', []);
    $arr = $db->fetchAll($res);
    var_dump($arr);

    $db->prepare('select_query', 'SELECT id, randomnumber FROM World WHERE id = $1');
    $res = $db->execute('select_query', [123]);
    $ret = $db->fetchAll($res);
    var_dump($ret);
});

You can find more examples in the /examples folder.

About

🐘 Coroutine-based client for PostgreSQL

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 84.2%
  • PHP 6.9%
  • M4 5.7%
  • C 2.3%
  • Shell 0.9%