Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.
/ ext-postgresql Public archive

🐘 Coroutine-based client for PostgreSQL

Notifications You must be signed in to change notification settings

swoole/ext-postgresql

Folders and files

NameName
Last commit message
Last commit date
Jan 11, 2021
Aug 10, 2021
Sep 27, 2021
Sep 13, 2020
Dec 14, 2020
Sep 21, 2020
Sep 21, 2020
Jan 7, 2022
Sep 21, 2020
Aug 3, 2020
Nov 4, 2021
Sep 21, 2020
Sep 28, 2022

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.