Conditions | 7 |
Paths | 23 |
Total Lines | 34 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 7 |
Changes | 3 | ||
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 | |||
45 | 9 | } catch (Exception\InvalidArgumentException $e) { |
|
46 | 5 | throw $e; |
|
47 | 2 | } catch (\Exception $e) { |
|
48 | 2 | $eclass = get_class($e); |
|
49 | 2 | $msg = "GenericPdo '$eclass' : {$e->getMessage()} [$query]"; |
|
50 | 2 | throw new Exception\InvalidArgumentException($msg); |
|
51 | } |
||
52 | 9 | return $results; |
|
53 | |||
54 | } |
||
55 | |||
77 |