MSSQLTrusting   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 15
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A connectToServer() 0 22 3
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Database\PDO;
4
5
6
use PDO;
7
8
9
/**
10
 * Class MSSQLTrusting
11
 * @package kalanis\kw_mapper\Storage\Database\PDO
12
 * Connection to Microsoft SQL, they based it on TransactSQL
13
 * Can be also used for Sybase DB, because they have similar base
14
 *
15
 * This extension is just to trust automatically to server certificates
16
 * @link https://stackoverflow.com/questions/71688125/odbc-driver-18-for-sql-serverssl-provider-error1416f086#72348333
17
 */
18
class MSSQLTrusting extends MSSQL
19
{
20
    protected function connectToServer(): PDO
21
    {
22
        $connection = new PDO(
23
            sprintf('sqlsrv:server=%s;Database=%s;TrustServerCertificate=yes;',
24
                $this->config->getLocation(),
25
                $this->config->getDatabase()
26
            ),
27
            $this->config->getUser(),
28
            $this->config->getPassword()
29
        );
30
31
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
32
33
        if ($this->config->isPersistent()) {
34
            $connection->setAttribute(PDO::ATTR_PERSISTENT, true);
35
        }
36
37
        foreach ($this->attributes as $key => $value){
38
            $connection->setAttribute($key, $value);
39
        }
40
41
        return $connection;
42
    }
43
}
44