| Conditions | 7 |
| Paths | 29 |
| Total Lines | 34 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | |||
| 74 |