PostgresConnector
class PostgresConnector extends Connector implements ConnectorInterface
Traits
Properties
| protected array | $options | The default PDO connection options. |
Methods
Determine if the given exception was caused by a lost connection.
Create a new PDO connection.
Create a new PDO connection instance.
Handle an exception that occurred during connect execution.
Parse the Postgres "search_path" configuration value into an array.
Create a DSN string from a configuration.
Build the libpq "options" parameter value from startup settings.
Escape a startup option value for use inside libpq's options parameter.
Add the SSL options to the DSN.
Format the search path as a quoted identifier list.
Details
in
DetectsLostConnections at line 16
protected bool
causedByLostConnection(Throwable $e)
Determine if the given exception was caused by a lost connection.
in
Connector at line 33
PDO
createConnection(string $dsn, array $config, array $options)
Create a new PDO connection.
in
Connector at line 60
protected PDO
createPdoConnection(string $dsn, string|null $username, string|null $password, array $options)
Create a new PDO connection instance.
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.
in
Connector at line 84
array
getOptions(array $config)
Get the PDO options based on the configuration.
in
Connector at line 94
array
getDefaultOptions()
Get the default PDO connection options.
in
Connector at line 102
void
setDefaultOptions(array $options)
Set the default PDO connection options.
in
ParsesSearchPath at line 12
protected array
parseSearchPath(string|array|null $searchPath)
Parse the Postgres "search_path" configuration value into an 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.
at line 46
protected string
getDsn(array $config)
Create a DSN string from a configuration.
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.
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).
at line 152
protected string
addSslOptions(string $dsn, array $config)
Add the SSL options to the DSN.
at line 166
protected string
quoteSearchPath(array $searchPath)
Format the search path as a quoted identifier list.