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
|
4575 |
|
public function __construct($dsn, $user = null, $password = null, ?array $options = null) |
25
|
|
|
{ |
26
|
|
|
try { |
27
|
4575 |
|
parent::__construct($dsn, (string) $user, (string) $password, (array) $options); |
28
|
4575 |
|
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); |
29
|
4575 |
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
30
|
3991 |
|
} catch (\PDOException $exception) { |
31
|
3991 |
|
throw new PDOException($exception); |
32
|
|
|
} |
33
|
4575 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
4563 |
|
public function exec($statement) |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
4563 |
|
return parent::exec($statement); |
42
|
4561 |
|
} catch (\PDOException $exception) { |
43
|
4561 |
|
throw new PDOException($exception); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
4110 |
|
public function getServerVersion() |
51
|
|
|
{ |
52
|
4110 |
|
return PDO::getAttribute(PDO::ATTR_SERVER_VERSION); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $prepareString |
57
|
|
|
* @param array<int, int> $driverOptions |
58
|
|
|
* |
59
|
|
|
* @return \PDOStatement |
60
|
|
|
*/ |
61
|
4470 |
|
public function prepare($prepareString, $driverOptions = []) |
62
|
|
|
{ |
63
|
|
|
try { |
64
|
4470 |
|
$statement = parent::prepare($prepareString, $driverOptions); |
65
|
4411 |
|
assert($statement instanceof \PDOStatement); |
66
|
|
|
|
67
|
4411 |
|
return $statement; |
|
|
|
|
68
|
4468 |
|
} catch (\PDOException $exception) { |
69
|
4468 |
|
throw new PDOException($exception); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
* |
76
|
|
|
* @return \PDOStatement |
77
|
|
|
*/ |
78
|
4542 |
|
public function query() |
79
|
|
|
{ |
80
|
4542 |
|
$args = func_get_args(); |
81
|
|
|
|
82
|
|
|
try { |
83
|
4542 |
|
$stmt = parent::query(...$args); |
|
|
|
|
84
|
4406 |
|
assert($stmt instanceof \PDOStatement); |
85
|
|
|
|
86
|
4406 |
|
return $stmt; |
|
|
|
|
87
|
4538 |
|
} catch (\PDOException $exception) { |
88
|
4538 |
|
throw new PDOException($exception); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
4156 |
|
public function quote($input, $type = ParameterType::STRING) |
96
|
|
|
{ |
97
|
4156 |
|
return parent::quote($input, $type); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
471 |
|
public function lastInsertId($name = null) |
104
|
|
|
{ |
105
|
|
|
try { |
106
|
471 |
|
if ($name === null) { |
107
|
129 |
|
return parent::lastInsertId(); |
108
|
|
|
} |
109
|
|
|
|
110
|
342 |
|
return parent::lastInsertId($name); |
111
|
|
|
} catch (\PDOException $exception) { |
112
|
|
|
throw new PDOException($exception); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
*/ |
119
|
4299 |
|
public function requiresQueryForServerVersion() |
120
|
|
|
{ |
121
|
4299 |
|
return false; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: