Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.PgFetchArrayIterator.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp;
8 
9 class PgFetchArrayIterator implements \Iterator
10 {
11  protected $row = 0;
12  protected $pgResultCount = 0;
13  protected $pgResult = null;
14 
15  public function __construct($pgResult)
16  {
17  $this->pgResult = $pgResult;
18  $this->pgResultCount = pg_num_rows($this->pgResult);
19  }
20  /**
21  * (PHP 5 &gt;= 5.0.0)<br/>
22  * Return the current element
23  * @link http://php.net/manual/en/iterator.current.php
24  * @return mixed Can return any type.
25  */
26  public function current()
27  {
28  return pg_fetch_array($this->pgResult, $this->row, PGSQL_BOTH);
29  }
30  /**
31  * (PHP 5 &gt;= 5.0.0)<br/>
32  * Move forward to next element
33  * @link http://php.net/manual/en/iterator.next.php
34  * @return void Any returned value is ignored.
35  */
36  public function next()
37  {
38  $this->row++;
39  }
40  /**
41  * (PHP 5 &gt;= 5.0.0)<br/>
42  * Return the key of the current element
43  * @link http://php.net/manual/en/iterator.key.php
44  * @return mixed scalar on success, or null on failure.
45  */
46  public function key()
47  {
48  return $this->row;
49  }
50  /**
51  * (PHP 5 &gt;= 5.0.0)<br/>
52  * Checks if current position is valid
53  * @link http://php.net/manual/en/iterator.valid.php
54  * @return boolean The return value will be casted to boolean and then evaluated.
55  * Returns true on success or false on failure.
56  */
57  public function valid()
58  {
59  return ($this->row < $this->pgResultCount);
60  }
61  /**
62  * (PHP 5 &gt;= 5.0.0)<br/>
63  * Rewind the Iterator to the first element
64  * @link http://php.net/manual/en/iterator.rewind.php
65  * @return void Any returned value is ignored.
66  */
67  public function rewind()
68  {
69  $this->row = 0;
70  }
71 }
← centre documentaire © anakeen