1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Driver; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\ParameterType; |
6
|
|
|
use PDO; |
7
|
|
|
use function assert; |
8
|
|
|
use function func_get_args; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* PDO implementation of the Connection interface. |
12
|
|
|
* Used by all PDO-based drivers. |
13
|
|
|
*/ |
14
|
|
|
class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param string $dsn |
18
|
|
|
* @param string|null $user |
19
|
|
|
* @param string|null $password |
20
|
|
|
* @param mixed[]|null $options |
21
|
|
|
* |
22
|
|
|
* @throws PDOException In case of an error. |
23
|
|
|
*/ |
24
|
1114 |
|
public function __construct($dsn, $user = null, $password = null, ?array $options = null) |
25
|
|
|
{ |
26
|
|
|
try { |
27
|
1114 |
|
parent::__construct($dsn, (string) $user, (string) $password, (array) $options); |
28
|
1075 |
|
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); |
29
|
1075 |
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
30
|
71 |
|
} catch (\PDOException $exception) { |
31
|
71 |
|
throw new PDOException($exception); |
32
|
|
|
} |
33
|
1075 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
3444 |
|
public function exec($statement) |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
3444 |
|
return parent::exec($statement); |
42
|
1984 |
|
} catch (\PDOException $exception) { |
43
|
1984 |
|
throw new PDOException($exception); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
425 |
|
public function getServerVersion() |
51
|
|
|
{ |
52
|
425 |
|
return PDO::getAttribute(PDO::ATTR_SERVER_VERSION); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
2617 |
|
public function prepare($prepareString, $driverOptions = []) |
59
|
|
|
{ |
60
|
|
|
try { |
61
|
2617 |
|
return parent::prepare($prepareString, $driverOptions); |
|
|
|
|
62
|
36 |
|
} catch (\PDOException $exception) { |
63
|
36 |
|
throw new PDOException($exception); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
3602 |
|
public function query() |
71
|
|
|
{ |
72
|
3602 |
|
$args = func_get_args(); |
73
|
|
|
|
74
|
|
|
try { |
75
|
3602 |
|
$stmt = parent::query(...$args); |
|
|
|
|
76
|
3483 |
|
assert($stmt instanceof \PDOStatement); |
77
|
|
|
|
78
|
3483 |
|
return $stmt; |
|
|
|
|
79
|
119 |
|
} catch (\PDOException $exception) { |
80
|
119 |
|
throw new PDOException($exception); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
159 |
|
public function quote($input, $type = ParameterType::STRING) |
88
|
|
|
{ |
89
|
159 |
|
return parent::quote($input, $type); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
95 |
|
public function lastInsertId($name = null) |
96
|
|
|
{ |
97
|
|
|
try { |
98
|
95 |
|
if ($name === null) { |
99
|
18 |
|
return parent::lastInsertId(); |
100
|
|
|
} |
101
|
|
|
|
102
|
77 |
|
return parent::lastInsertId($name); |
103
|
|
|
} catch (\PDOException $exception) { |
104
|
|
|
throw new PDOException($exception); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
442 |
|
public function requiresQueryForServerVersion() |
112
|
|
|
{ |
113
|
442 |
|
return false; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: