1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage database
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 *
8 * This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning FOFTable objects
9 * instead of plain stdClass objects
10 */
11
12 // Protect from unauthorized access
13 defined('FOF_INCLUDED') or die;
14
15 /**
16 * PDO database iterator.
17 */
18 class FOFDatabaseIteratorPdo extends FOFDatabaseIterator
19 {
20 /**
21 * Get the number of rows in the result set for the executed SQL given by the cursor.
22 *
23 * @return integer The number of rows in the result set.
24 *
25 * @see Countable::count()
26 */
27 public function count()
28 {
29 if (!empty($this->cursor) && $this->cursor instanceof PDOStatement)
30 {
31 return @$this->cursor->rowCount();
32 }
33 else
34 {
35 return 0;
36 }
37 }
38
39 /**
40 * Method to fetch a row from the result set cursor as an object.
41 *
42 * @return mixed Either the next row from the result set or false if there are no more rows.
43 */
44 protected function fetchObject()
45 {
46 if (!empty($this->cursor) && $this->cursor instanceof PDOStatement)
47 {
48 return @$this->cursor->fetchObject($this->class);
49 }
50 else
51 {
52 return false;
53 }
54 }
55
56 /**
57 * Method to free up the memory used for the result set.
58 *
59 * @return void
60 */
61 protected function freeResult()
62 {
63 if (!empty($this->cursor) && $this->cursor instanceof PDOStatement)
64 {
65 @$this->cursor->closeCursor();
66 }
67 }
68 }
69