|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Driver\IBMDB2; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Driver\AbstractDB2Driver; |
|
6
|
|
|
use Doctrine\DBAL\Driver\Connection; |
|
7
|
|
|
use function implode; |
|
8
|
|
|
use function sprintf; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* IBM DB2 Driver. |
|
12
|
|
|
*/ |
|
13
|
|
|
class DB2Driver extends AbstractDB2Driver |
|
14
|
|
|
{ |
|
15
|
20 |
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
20 |
|
*/ |
|
18
|
20 |
|
public function connect( |
|
19
|
|
|
array $params, |
|
20
|
|
|
array $driverOptions = [] |
|
21
|
20 |
|
) : Connection { |
|
22
|
|
|
if (! isset($params['protocol'])) { |
|
23
|
|
|
$params['protocol'] = 'TCPIP'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
// if the host isn't localhost, use extended connection params |
|
27
|
|
|
if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') { |
|
28
|
|
|
$dsnParams = [ |
|
29
|
|
|
'DRIVER' => '{IBM DB2 ODBC DRIVER}', |
|
30
|
|
|
'DATABASE' => $params['dbname'], |
|
31
|
|
|
'HOSTNAME' => $params['host'], |
|
32
|
|
|
'PROTOCOL' => $params['protocol'], |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
if (isset($params['username'])) { |
|
36
|
|
|
$dsnParams['UID'] = $params['username']; |
|
37
|
20 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
if (isset($params['password'])) { |
|
40
|
|
|
$dsnParams['PWD'] = $params['password']; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
45 |
|
if (isset($params['port'])) { |
|
44
|
|
|
$dsnParams['PORT'] = $params['port']; |
|
45
|
45 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
$pairs = []; |
|
48
|
|
|
|
|
49
|
|
|
foreach ($dsnParams as $param => $value) { |
|
50
|
|
|
$pairs[] = sprintf('%s=%s', $param, $value); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$params['dbname'] = implode(';', $pairs); |
|
54
|
|
|
|
|
55
|
|
|
unset($params['username'], $params['password']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return new DB2Connection($params, $driverOptions); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getName() : string |
|
65
|
|
|
{ |
|
66
|
|
|
return 'ibm_db2'; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|