From 62aa1d181e3bba5b1d4a2485f2dc5a8b397908a9 Mon Sep 17 00:00:00 2001 From: muhme Date: Mon, 7 Oct 2024 16:27:48 +0200 Subject: [PATCH] Allow IPv6 addresses with brackets for pgsql This unifies with MySQL and MariaDB and allows to set port number. --- src/Pdo/PdoDriver.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Pdo/PdoDriver.php b/src/Pdo/PdoDriver.php index 6bdfe857..8a3108a4 100644 --- a/src/Pdo/PdoDriver.php +++ b/src/Pdo/PdoDriver.php @@ -261,6 +261,12 @@ public function connect() // Extract host and port or socket from host option $this->setHostPortSocket(5432); + // PostgreSQL (in difference to MariaDB and MySQL) does not work with + // IPv6 addresses enclosed in square brackets, so we simply remove them here. + if (isset($this->options['host']) && substr($this->options['host'], 0, 1) === '[' && substr($this->options['host'], -1) === ']') { + $this->options['host'] = trim($this->options['host'], '[]'); + } + if ($this->options['socket'] !== null) { $format = 'pgsql:host=#SOCKET#;dbname=#DBNAME#'; } else {