Swoole\Coroutine\PostgreSQL->connect(...)

Declaration

<?php
Swoole\Coroutine\PostgreSQL->connect(string $connectionString): bool

Parameters

connectionString

Pass in the Postgres connection string used to connect to the server and database.

Return

Returns true if there were no connection errors and false when there was a problem. Check the error message.


Description

Establish a postgresql non-blocking connection within a coroutine context.

The example shows you how to deal with connection errors.


Example

<?php

use Swoole\Coroutine\PostgreSQL;

Co\run(function()
{
    $pg = new PostgreSQL();
    $conn = $pg->connect("host=127.0.0.1;port=5432;dbname=test;user=postgres;password=***");
    var_dump($pg->error, $conn);
});