Skip to content

Commit 9e50503

Browse files
committed
Fix MSSQL CI /w ODBC v18.0
1 parent b3e06bc commit 9e50503

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.github/workflows/test-unit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
207207
- name: "Run tests: MSSQL"
208208
env:
209-
DB_DSN: "sqlsrv:host=mssql;dbname=master"
209+
DB_DSN: "sqlsrv:host=mssql;dbname=master;driverOptions[TrustServerCertificate]=1"
210210
DB_USER: sa
211211
DB_PASSWORD: atk4_pass
212212
run: |

src/Persistence/Sql/Connection.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ public static function normalizeDsn($dsn, $user = null, $password = null)
114114
} else {
115115
foreach (explode(';', $parts[1] ?? '') as $part) {
116116
[$k, $v] = str_contains($part, '=') ? explode('=', $part, 2) : [$part, null];
117-
$dsn[$k] = $v;
117+
if ($k === 'query' || str_contains($part, '[')) {
118+
parse_str($k === 'query' ? $v : $part, $partRes);
119+
foreach ($partRes as $pK => $pV) {
120+
$dsn[$pK] = $pV;
121+
}
122+
} else {
123+
$dsn[$k] = $v;
124+
}
118125
}
119126
if (isset($dsn['host']) && str_contains($dsn['host'], ':')) {
120127
[$dsn['host'], $port] = explode(':', $dsn['host'], 2);

tests/Persistence/Sql/ConnectionTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ public function testDsnNormalize(): void
9191
$dsn = Connection::normalizeDsn('mysql:host=localhost:1234;dbname=db');
9292
$this->assertSame(['driver' => 'mysqli', 'host' => 'localhost', 'dbname' => 'db', 'port' => '1234'], $dsn);
9393

94+
// driverOptions array
95+
$dsn = Connection::normalizeDsn('mysql://localhost:1234/db?driverOptions[TrustServerCertificate]=1');
96+
$this->assertSame(['driver' => 'mysqli', 'host' => 'localhost', 'port' => '1234', 'driverOptions' => ['TrustServerCertificate' => '1'], 'dbname' => 'db'], $dsn);
97+
98+
$dsn = Connection::normalizeDsn('mysql:host=localhost:1234;dbname=db;driverOptions[TrustServerCertificate]=1');
99+
$this->assertSame(['driver' => 'mysqli', 'host' => 'localhost', 'dbname' => 'db', 'driverOptions' => ['TrustServerCertificate' => '1'], 'port' => '1234'], $dsn);
100+
94101
// full PDO and native driver names
95102
$dsn = Connection::normalizeDsn('pdo-mysql://root:pass@localhost/db');
96103
$this->assertSame(['driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'pass', 'dbname' => 'db'], $dsn);

0 commit comments

Comments
 (0)