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