Conditions | 7 |
Paths | 29 |
Total Lines | 35 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 7 |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
21 | 9 | public function query($query) |
|
22 | { |
||
23 | try { |
||
24 | //$query = "select * from product"; |
||
25 | 9 | $stmt = $this->resource->prepare($query); |
|
26 | |||
27 | 9 | if ($stmt === false) { |
|
28 | 1 | $error = $this->resource->errorInfo(); |
|
29 | 1 | throw new Exception\InvalidArgumentException($error[2]); |
|
30 | } |
||
31 | |||
32 | 9 | if (!$stmt->execute()) { |
|
33 | 4 | throw new Exception\InvalidArgumentException( |
|
34 | 4 | 'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')' |
|
35 | 4 | ); |
|
36 | }; |
||
37 | |||
38 | 9 | $results = new Resultset(); |
|
39 | 9 | if ($stmt->columnCount() > 0) { |
|
40 | 5 | while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
41 | 5 | $results->append($row); |
|
42 | 5 | } |
|
43 | 5 | } |
|
44 | 9 | $stmt->closeCursor(); |
|
45 | |||
46 | 9 | } catch (Exception\InvalidArgumentException $e) { |
|
47 | 5 | throw $e; |
|
48 | 2 | } catch (\Exception $e) { |
|
49 | 2 | $eclass = get_class($e); |
|
50 | 2 | $msg = "GenericPdo '$eclass' : {$e->getMessage()} [$query]"; |
|
51 | 2 | throw new Exception\InvalidArgumentException($msg); |
|
52 | } |
||
53 | 9 | return $results; |
|
54 | |||
55 | } |
||
56 | |||
78 |