1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lib\DB\DBAL\Connection; |
6
|
|
|
|
7
|
|
|
use Lib\DB\DBAL\FetchMode; |
8
|
|
|
use PDO; |
9
|
|
|
|
10
|
|
|
class PDOConnection extends PDO implements ConnectionInterface |
11
|
|
|
{ |
12
|
|
|
// @codeCoverageIgnoreStart |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
public function prepare($prepareString, $driverOptions = null) |
18
|
|
|
{ |
19
|
|
|
try { |
20
|
|
|
parent::prepare($prepareString, $driverOptions); |
21
|
|
|
} catch (\PDOException $e) { |
22
|
|
|
throw new \PDOException($e); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function query($query, $mode = FetchMode::DEFAULT, $arg3 = null, array $ctorargs = []) |
30
|
|
|
{ |
31
|
|
|
$argsCount = \count(\func_get_args()); |
32
|
|
|
try { |
33
|
|
|
if ($argsCount === 4) { |
34
|
|
|
return parent::query($query, $mode, $arg3, $ctorargs); |
35
|
|
|
} |
36
|
|
|
if ($argsCount === 3) { |
37
|
|
|
return parent::query($query, $mode, $arg3); |
38
|
|
|
} |
39
|
|
|
if ($argsCount === 2) { |
40
|
|
|
return parent::query($query, $mode); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return parent::query($query); |
44
|
|
|
} catch (\PDOException $e) { |
45
|
|
|
throw new \PDOException($e); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function exec($statement) |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
parent::exec($statement); |
56
|
|
|
} catch (\PDOException $e) { |
57
|
|
|
throw new \PDOException($e); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function lastInsertId($name = null) |
65
|
|
|
{ |
66
|
|
|
try { |
67
|
|
|
parent::lastInsertId($name); |
68
|
|
|
} catch (\PDOException $e) { |
69
|
|
|
throw new \PDOException($e); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function beginTransaction() |
77
|
|
|
{ |
78
|
|
|
try { |
79
|
|
|
parent::beginTransaction(); |
80
|
|
|
} catch (\PDOException $e) { |
81
|
|
|
throw new \PDOException($e); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function commit() |
89
|
|
|
{ |
90
|
|
|
try { |
91
|
|
|
parent::commit(); |
92
|
|
|
} catch (\PDOException $e) { |
93
|
|
|
throw new \PDOException($e); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function rollBack() |
101
|
|
|
{ |
102
|
|
|
try { |
103
|
|
|
parent::rollBack(); |
104
|
|
|
} catch (\PDOException $e) { |
105
|
|
|
throw new \PDOException($e); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// @codeCoverageIgnoreEnd |
110
|
|
|
} |
111
|
|
|
|