3000 explained code solutions for 75 technologies


php-swoolePostgreSQL connect and query example


Co\run(function() {

  $pg = new Swoole\Coroutine\PostgreSQL();
  $pg->connect('host=127.0.0.1;port=5432;dbname=db;user=u;password=p');

  go(function () use ($pg) {
    $res = $pg->query('SELECT CURRENT_DATE;');
    print_r($pg->fetchAll($res));
  });

});ctrl + c
Swoole\Coroutine\PostgreSQL

Postgres client for Swoole

$pg->connect

init connection to DB

$pg->query

execute sample query

print_r($pg->fetchAll($res))

print fetched results from DB