1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Storage\Database\PDO; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\Storage\Database\Dialects; |
7
|
|
|
use PDO; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class MSSQL |
12
|
|
|
* @package kalanis\kw_mapper\Storage\Database\PDO |
13
|
|
|
* Connection to Microsoft SQL, they based it on TransactSQL |
14
|
|
|
* Can be also used for Sybase DB, because they have similar base |
15
|
|
|
* |
16
|
|
|
* To make driver on Linux use following pages: |
17
|
|
|
* @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php |
18
|
|
|
* @link https://github.com/microsoft/msphpsql |
19
|
|
|
* @link https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver16&tabs=cli&pivots=cs1-bash |
20
|
|
|
* |
21
|
|
|
* Also beware that MS needs explicitly state name of column for "ORDER BY" when you use "OFFSET"-"LIMIT" |
22
|
|
|
*/ |
23
|
|
|
class MSSQL extends APDO |
24
|
|
|
{ |
25
|
|
|
protected string $extension = 'pdo_sqlsrv'; |
26
|
|
|
|
27
|
|
|
public function languageDialect(): string |
28
|
|
|
{ |
29
|
|
|
return Dialects\TransactSQL::class; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function connectToServer(): PDO |
33
|
|
|
{ |
34
|
|
|
$connection = new PDO( |
35
|
|
|
sprintf('sqlsrv:server=%s;Database=%s;', |
36
|
|
|
$this->config->getLocation(), |
37
|
|
|
$this->config->getDatabase() |
38
|
|
|
), |
39
|
|
|
$this->config->getUser(), |
40
|
|
|
$this->config->getPassword() |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
44
|
|
|
|
45
|
|
|
if ($this->config->isPersistent()) { |
46
|
|
|
$connection->setAttribute(PDO::ATTR_PERSISTENT, true); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
foreach ($this->attributes as $key => $value){ |
50
|
|
|
$connection->setAttribute($key, $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $connection; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|