Total Complexity | 3 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class PDOQuery extends Query |
||
13 | { |
||
14 | /** |
||
15 | * The internal MySQL handle that points to the result set. |
||
16 | * @var PDOStatement |
||
17 | */ |
||
18 | protected $statement = null; |
||
19 | |||
20 | protected $results = null; |
||
21 | |||
22 | /** |
||
23 | * Hook the result-set given into a Query class, suitable for use by SilverStripe. |
||
24 | * @param PDOStatement $statement The internal PDOStatement containing the results |
||
25 | */ |
||
26 | public function __construct(PDOStatement $statement) |
||
27 | { |
||
28 | $this->statement = $statement; |
||
29 | // Since no more than one PDOStatement for any one connection can be safely |
||
30 | // traversed, each statement simply requests all rows at once for safety. |
||
31 | // This could be re-engineered to call fetchAll on an as-needed basis |
||
32 | $this->results = $statement->fetchAll(PDO::FETCH_ASSOC); |
||
33 | $statement->closeCursor(); |
||
34 | } |
||
35 | |||
36 | public function getIterator() |
||
37 | { |
||
38 | return new ArrayIterator($this->results); |
||
39 | } |
||
40 | |||
41 | public function numRecords() |
||
44 | } |
||
45 | } |
||
46 |