1 | <?php |
||
16 | class PreparedPDOStatement implements PreparedStatement |
||
17 | { |
||
18 | /** |
||
19 | * @var PDOStatement |
||
20 | */ |
||
21 | private $handle; |
||
22 | |||
23 | /** |
||
24 | * @var PDOExceptionMapper |
||
25 | */ |
||
26 | private $exception_mapper; |
||
27 | |||
28 | /** |
||
29 | * @var TypeProvider |
||
30 | */ |
||
31 | private $types; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $params = []; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $executed = false; |
||
42 | |||
43 | /** |
||
44 | * @var Logger |
||
45 | */ |
||
46 | private $logger; |
||
47 | |||
48 | /** |
||
49 | * @param PDOStatement $handle |
||
50 | * @param PDOExceptionMapper $exception_mapper |
||
51 | * @param TypeProvider $types |
||
52 | * @param Logger $logger |
||
53 | */ |
||
54 | 1 | public function __construct( |
|
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | 1 | public function bind($name, $value) |
|
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | 1 | public function execute() |
|
104 | { |
||
105 | 1 | $microtime_begin = microtime(true); |
|
106 | |||
107 | 1 | if (@$this->handle->execute()) { |
|
108 | 1 | $this->executed = true; |
|
109 | 1 | $microtime_end = microtime(true); |
|
110 | 1 | $time_msec = ($microtime_end - $microtime_begin) * 1000; |
|
111 | 1 | $this->logger->logQuery($this->handle->queryString, $this->params, $time_msec); |
|
112 | } else { |
||
113 | list($sql_state, $error_code, $error_message) = $this->handle->errorInfo(); |
||
114 | |||
115 | $exception_type = $this->exception_mapper->getExceptionType($sql_state, $error_code, $error_message); |
||
116 | |||
117 | throw new $exception_type( |
||
118 | $this->handle->queryString, |
||
119 | $this->params, |
||
120 | "{$sql_state}: {$error_message}", |
||
121 | $error_code |
||
122 | ); |
||
123 | } |
||
124 | 1 | } |
|
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | 1 | public function fetch() |
|
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | public function getRowsAffected() |
||
151 | } |
||
152 |