| 1 | <?php |
||
| 9 | class MysqliAdapter implements AdapterInterface |
||
| 10 | { |
||
| 11 | |||
| 12 | use Mysql\MysqlCommonTrait; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * |
||
| 16 | * @var \mysqli |
||
| 17 | */ |
||
| 18 | protected $resource; |
||
| 19 | |||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor |
||
| 23 | * |
||
| 24 | * @param mysqli $connection |
||
| 25 | */ |
||
| 26 | 6 | public function __construct(mysqli $connection) |
|
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | 1 | public function quoteValue($value) |
|
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | 3 | public function query($query) |
|
| 45 | { |
||
| 46 | try { |
||
| 47 | 3 | $r = $this->resource->query($query); |
|
| 48 | |||
| 49 | 3 | $results = new Resultset(); |
|
| 50 | |||
| 51 | 3 | if ($r === false) { |
|
| 52 | 2 | throw new Exception\InvalidArgumentException("Query cannot be executed [$query]."); |
|
| 53 | 3 | } elseif ($r !== true && !$r instanceof \mysqli_result) { |
|
| 54 | throw new Exception\InvalidArgumentException("Query didn't return any result [$query]."); |
||
| 55 | 3 | } elseif ($r instanceof \mysqli_result) { |
|
| 56 | 2 | while ($row = $r->fetch_assoc()) { |
|
| 57 | 2 | $results->append($row); |
|
| 58 | 2 | } |
|
| 59 | 2 | } |
|
| 60 | 3 | } catch (Exception\InvalidArgumentException $e) { |
|
| 61 | 2 | throw $e; |
|
| 62 | } catch (\Exception $e) { |
||
| 63 | $msg = "MysqliException: {$e->getMessage()} [$query]"; |
||
| 64 | throw new Exception\InvalidArgumentException($msg); |
||
| 65 | } |
||
| 66 | 3 | return $results; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | 2 | public function execute($query) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * {@ineritdoc} |
||
| 79 | * @return \mysqli |
||
| 80 | */ |
||
| 81 | 1 | public function getResource() |
|
| 85 | } |
||
| 86 |