class PostgresConnector extends Connector implements ConnectorInterface

Traits

Properties

protected array $options

The default PDO connection options.

Methods

bool
causedByLostConnection(Throwable $e)

Determine if the given exception was caused by a lost connection.

PDO
createConnection(string $dsn, array $config, array $options)

Create a new PDO connection.

PDO
createPdoConnection(string $dsn, string|null $username, string|null $password, array $options)

Create a new PDO connection instance.

PDO
tryAgainIfCausedByLostConnection(Throwable $e, string $dsn, string|null $username, string|null $password, array $options)

Handle an exception that occurred during connect execution.

array
getOptions(array $config)

Get the PDO options based on the configuration.

array
getDefaultOptions()

Get the default PDO connection options.

void
setDefaultOptions(array $options)

Set the default PDO connection options.

int|null
getLockTimeout(array $config)

Get the configured lock timeout in seconds.

array
parseSearchPath(string|array|null $searchPath)

Parse the Postgres "search_path" configuration value into an array.

PDO
connect(array $config)

Establish a database connection.

string
getDsn(array $config)

Create a DSN string from a configuration.

string
addServerOptions(string $dsn, array $config)

Add the server options to the DSN.

string
escapeStartupOptionValue(string $value)

Escape a value for the server's options argument splitter.

string
quoteConnectionValue(string $value)

Quote a value for libpq's connection-string parser.

string
addSslOptions(string $dsn, array $config)

Add the SSL options to the DSN.

string
addKeepaliveOptions(string $dsn, array $config)

Add the keepalive options to the DSN.

string
quoteSearchPath(array $searchPath)

Format the search path as a quoted identifier list.

Details

protected bool causedByLostConnection(Throwable $e)

Determine if the given exception was caused by a lost connection.

Parameters

Throwable $e

Return Value

bool

in Connector at line 36
PDO createConnection(string $dsn, array $config, array $options)

Create a new PDO connection.

Parameters

string $dsn
array $config
array $options

Return Value

PDO

Exceptions

Exception

in Connector at line 67
protected PDO createPdoConnection(string $dsn, string|null $username, string|null $password, array $options)

Create a new PDO connection instance.

Parameters

string $dsn
string|null $username
string|null $password
array $options

Return Value

PDO

in Connector at line 87
protected PDO tryAgainIfCausedByLostConnection(Throwable $e, string $dsn, string|null $username, string|null $password, array $options)

Handle an exception that occurred during connect execution.

Parameters

Throwable $e
string $dsn
string|null $username
string|null $password
array $options

Return Value

PDO

Exceptions

Throwable

at line 51
array getOptions(array $config)

Get the PDO options based on the configuration.

Parameters

array $config

Return Value

array

in Connector at line 109
array getDefaultOptions()

Get the default PDO connection options.

Return Value

array

in Connector at line 117
void setDefaultOptions(array $options)

Set the default PDO connection options.

Parameters

array $options

Return Value

void

in Connector at line 125
protected int|null getLockTimeout(array $config)

Get the configured lock timeout in seconds.

Parameters

array $config

Return Value

int|null

in ParsesSearchPath at line 12
protected array parseSearchPath(string|array|null $searchPath)

Parse the Postgres "search_path" configuration value into an array.

Parameters

string|array|null $searchPath

Return Value

array

at line 35
PDO connect(array $config)

Establish a database connection.

Startup parameters (search_path, timezone, isolation level, synchronous commit) are baked into the DSN via libpq's "options" parameter rather than issued as post-connect SET statements. This keeps them intact on pooled connections (PgBouncer transaction pooling, pgdog, etc.) where a SET applied to one backend is lost when the pooler hands the next query to a different backend.

Parameters

array $config

Return Value

PDO

at line 66
protected string getDsn(array $config)

Create a DSN string from a configuration.

Parameters

array $config

Return Value

string

at line 110
protected string addServerOptions(string $dsn, array $config)

Add the server options to the DSN.

Parameters

string $dsn
array $config

Return Value

string

at line 151
protected string escapeStartupOptionValue(string $value)

Escape a value for the server's options argument splitter.

Parameters

string $value

Return Value

string

at line 159
protected string quoteConnectionValue(string $value)

Quote a value for libpq's connection-string parser.

Parameters

string $value

Return Value

string

at line 167
protected string addSslOptions(string $dsn, array $config)

Add the SSL options to the DSN.

Parameters

string $dsn
array $config

Return Value

string

at line 181
protected string addKeepaliveOptions(string $dsn, array $config)

Add the keepalive options to the DSN.

Parameters

string $dsn
array $config

Return Value

string

at line 195
protected string quoteSearchPath(array $searchPath)

Format the search path as a quoted identifier list.

Parameters

array $searchPath

Return Value

string