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.

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|null
buildStartupOptions(array $config)

Build the libpq "options" parameter value from startup settings.

string
escapeStartupOptionValue(string $value)

Escape a startup option value for use inside libpq's options parameter.

string
addSslOptions(string $dsn, array $config)

Add the SSL 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 33
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 60
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 72
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

in Connector at line 84
array getOptions(array $config)

Get the PDO options based on the configuration.

Parameters

array $config

Return Value

array

in Connector at line 94
array getDefaultOptions()

Get the default PDO connection options.

Return Value

array

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

Set the default PDO connection options.

Parameters

array $options

Return Value

void

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 34
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 46
protected string getDsn(array $config)

Create a DSN string from a configuration.

Parameters

array $config

Return Value

string

at line 102
protected string|null buildStartupOptions(array $config)

Build the libpq "options" parameter value from startup settings.

Returns null when no startup settings are configured. Each setting is expressed as a "-c key=value" flag, space-separated. Values containing spaces (e.g. "read committed") are backslash-escaped so libpq preserves them as a single token when it splits the options string on whitespace.

Parameters

array $config

Return Value

string|null

at line 144
protected string escapeStartupOptionValue(string $value)

Escape a startup option value for use inside libpq's options parameter.

libpq splits the options string on unescaped whitespace, so spaces that belong to a single value (like the space in "read committed") must be backslash-escaped to stay part of that value rather than being treated as a token separator.

The replacement emits two backslashes before each space. PDO's DSN parser consumes one level of backslash-escaping when it extracts the single-quoted options value, so a single backslash in the DSN source is stripped before libpq sees it — leaving libpq to split on the unescaped space. Doubling the backslash survives PDO's unescape and arrives at libpq as a single \ (escaped space).

Parameters

string $value

Return Value

string

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

Add the SSL options to the DSN.

Parameters

string $dsn
array $config

Return Value

string

at line 166
protected string quoteSearchPath(array $searchPath)

Format the search path as a quoted identifier list.

Parameters

array $searchPath

Return Value

string