Exceptions
1 year ago
Connection.php
1 year ago
ConvertParameters.php
1 year ago
Driver.php
1 year ago
Result.php
2 months ago
Statement.php
1 year ago
index.php
1 year ago
Result.php
76 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Doctrine\WPDB; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\Doctrine\DBAL\Driver\Result as ResultInterface; |
| 9 | |
| 10 | /** |
| 11 | * WPDB fetches all results from the underlying database driver, |
| 12 | * so we need to implement the result methods on in-memory data. |
| 13 | */ |
| 14 | class Result implements ResultInterface { |
| 15 | /** @var array[] */ |
| 16 | private array $result = []; |
| 17 | private int $rowCount; |
| 18 | private int $cursor = 0; |
| 19 | |
| 20 | public function __construct( |
| 21 | array $result, |
| 22 | int $rowCount |
| 23 | ) { |
| 24 | foreach ($result as $row) { |
| 25 | $this->result[] = (array)$row; |
| 26 | } |
| 27 | $this->rowCount = $rowCount; |
| 28 | } |
| 29 | |
| 30 | public function fetchNumeric() { |
| 31 | $row = $this->result[$this->cursor++] ?? null; |
| 32 | return $row === null ? false : array_values($row); |
| 33 | } |
| 34 | |
| 35 | public function fetchAssociative() { |
| 36 | return $this->result[$this->cursor++] ?? false; |
| 37 | } |
| 38 | |
| 39 | public function fetchOne() { |
| 40 | $row = $this->result[$this->cursor++] ?? null; |
| 41 | return $row === null ? false : reset($row); |
| 42 | } |
| 43 | |
| 44 | public function fetchAllNumeric(): array { |
| 45 | $result = []; |
| 46 | foreach ($this->result as $row) { |
| 47 | $result[] = array_values($row); |
| 48 | } |
| 49 | return $result; |
| 50 | } |
| 51 | |
| 52 | public function fetchAllAssociative(): array { |
| 53 | return array_values($this->result); |
| 54 | } |
| 55 | |
| 56 | public function fetchFirstColumn(): array { |
| 57 | $result = []; |
| 58 | foreach ($this->result as $row) { |
| 59 | $result[] = reset($row); |
| 60 | } |
| 61 | return $result; |
| 62 | } |
| 63 | |
| 64 | public function rowCount(): int { |
| 65 | return $this->rowCount; |
| 66 | } |
| 67 | |
| 68 | public function columnCount(): int { |
| 69 | return count($this->result[0] ?? []); |
| 70 | } |
| 71 | |
| 72 | public function free(): void { |
| 73 | $this->cursor = 0; |
| 74 | } |
| 75 | } |
| 76 |