1 | <?php |
||
7 | class PdoConnection implements ConnectionInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var \PDO |
||
11 | */ |
||
12 | private $pdo; |
||
13 | |||
14 | private $dsn; |
||
15 | |||
16 | 11 | public function __construct($dsn) |
|
20 | |||
21 | 7 | public function query($query) |
|
22 | { |
||
23 | 5 | $this->initialize(); |
|
24 | |||
25 | try { |
||
26 | 2 | $stmt = $this->pdo->query($query); |
|
27 | } catch (\PDOException $e) { |
||
28 | throw new ConnectionException($e->getMessage(), 0, $e); |
||
29 | 4 | } |
|
30 | |||
31 | 2 | $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
|
32 | |||
33 | 6 | return $result; |
|
34 | } |
||
35 | |||
36 | 3 | public function multiQuery($query, array $resultSetNames = array()) |
|
37 | { |
||
38 | 1 | $this->initialize(); |
|
39 | |||
40 | try { |
||
41 | 1 | $stmt = $this->pdo->query($query); |
|
42 | } catch (\PDOException $e) { |
||
43 | throw new ConnectionException($e->getMessage(), 0, $e); |
||
44 | 2 | } |
|
45 | |||
46 | 3 | $results = array(); |
|
47 | 3 | $i = 0; |
|
48 | do { |
||
49 | 1 | $key = isset($resultSetNames[$i]) ? $resultSetNames[$i] : $i; |
|
50 | 1 | $results[$key] = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
|
51 | 1 | ++$i; |
|
52 | 1 | } while ($stmt->nextRowset()); |
|
53 | |||
54 | 3 | return $results; |
|
55 | 2 | } |
|
56 | |||
57 | 1 | public function exec($query) |
|
67 | |||
68 | public function quote($value) |
||
78 | |||
79 | 9 | protected function initialize() |
|
89 | } |
||
90 |