MediaWiki REL1_33
ResultWrapper.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use stdClass;
6use RuntimeException;
7
24class ResultWrapper implements IResultWrapper {
26 public $result;
27
29 protected $db;
30
32 protected $pos = 0;
34 protected $currentRow = null;
35
45 public function __construct( IDatabase $db = null, $result ) {
46 $this->db = $db;
47 if ( $result instanceof ResultWrapper ) {
48 $this->result = $result->result;
49 } else {
50 $this->result = $result;
51 }
52 }
53
54 public function numRows() {
55 return $this->getDB()->numRows( $this );
56 }
57
58 public function fetchObject() {
59 return $this->getDB()->fetchObject( $this );
60 }
61
62 public function fetchRow() {
63 return $this->getDB()->fetchRow( $this );
64 }
65
66 public function seek( $row ) {
67 $this->getDB()->dataSeek( $this, $row );
68 }
69
70 public function free() {
71 if ( $this->db ) {
72 $this->db = null;
73 }
74 $this->result = null;
75 }
76
81 private function getDB() {
82 if ( !$this->db ) {
83 throw new RuntimeException( static::class . ' needs a DB handle for iteration.' );
84 }
85
86 return $this->db;
87 }
88
89 function rewind() {
90 if ( $this->numRows() ) {
91 $this->getDB()->dataSeek( $this, 0 );
92 }
93 $this->pos = 0;
94 $this->currentRow = null;
95 }
96
97 function current() {
98 if ( is_null( $this->currentRow ) ) {
99 $this->next();
100 }
101
102 return $this->currentRow;
103 }
104
105 function key() {
106 return $this->pos;
107 }
108
109 function next() {
110 $this->pos++;
111 $this->currentRow = $this->fetchObject();
112
113 return $this->currentRow;
114 }
115
116 function valid() {
117 return $this->current() !== false;
118 }
119}
120
124class_alias( ResultWrapper::class, 'ResultWrapper' );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Result wrapper for grabbing data queried from an IDatabase object.
seek( $row)
Change the position of the cursor in a result object.
__construct(IDatabase $db=null, $result)
Create a row iterator from a result resource and an optional Database object.
free()
Free a result object.
fetchObject()
Fetch the next row from the given result object, in object form.
resource array null $result
Optional underlying result handle for subclass usage.
fetchRow()
Fetch the next row from the given result object, in associative array form.
numRows()
Get the number of rows in a result object.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Result wrapper for grabbing data queried from an IDatabase object.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))