1 | <?php |
||
9 | abstract class GenericPdo implements AdapterInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var \PDO |
||
13 | */ |
||
14 | protected $resource; |
||
15 | |||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 10 | public function query($query, $resultsetType = Resultset::TYPE_ARRAY) |
|
20 | { |
||
21 | try { |
||
22 | //$query = "select * from product"; |
||
23 | 10 | $stmt = $this->resource->prepare($query); |
|
24 | |||
25 | 10 | if ($stmt === false) { |
|
26 | 1 | $error = $this->resource->errorInfo(); |
|
27 | 1 | throw new Exception\InvalidArgumentException($error[2]); |
|
28 | } |
||
29 | |||
30 | 10 | if (!$stmt->execute()) { |
|
31 | 4 | throw new Exception\InvalidArgumentException( |
|
32 | 4 | 'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')' |
|
33 | ); |
||
34 | } |
||
35 | |||
36 | 10 | $results = new Resultset($resultsetType); |
|
37 | 10 | if ($stmt->columnCount() > 0) { |
|
38 | 6 | while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
39 | 6 | $results->append($row); |
|
40 | } |
||
41 | } |
||
42 | 10 | $stmt->closeCursor(); |
|
43 | 5 | } catch (Exception\InvalidArgumentException $e) { |
|
44 | 5 | throw $e; |
|
45 | 2 | } catch (\Exception $e) { |
|
46 | 2 | $eclass = get_class($e); |
|
47 | 2 | $msg = "GenericPdo '$eclass' : {$e->getMessage()} [$query]"; |
|
48 | 2 | throw new Exception\InvalidArgumentException($msg); |
|
49 | } |
||
50 | |||
51 | 10 | return $results; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 3 | public function quoteValue($value) |
|
61 | |||
62 | /** |
||
63 | * Check extension. |
||
64 | * |
||
65 | * @throws Exception\RuntimeException |
||
66 | */ |
||
67 | 20 | protected function checkEnvironment() |
|
73 | } |
||
74 |