3 * Result wrapper for grabbing data queried by someone else
6 class ResultWrapper
implements Iterator
{
10 /** @var DatabaseBase */
16 /** @var object|null */
17 protected $currentRow = null;
20 * Create a new result object from a result resource and a Database object
22 * @param DatabaseBase $database
23 * @param resource|ResultWrapper $result
25 function __construct( $database, $result ) {
26 $this->db
= $database;
28 if ( $result instanceof ResultWrapper
) {
29 $this->result
= $result->result
;
31 $this->result
= $result;
36 * Get the number of rows in a result object
41 return $this->db
->numRows( $this );
45 * Fetch the next row from the given result object, in object form. Fields can be retrieved with
46 * $row->fieldname, with fields acting like member variables. If no more rows are available,
49 * @return stdClass|bool
50 * @throws DBUnexpectedError Thrown if the database returns an error
52 function fetchObject() {
53 return $this->db
->fetchObject( $this );
57 * Fetch the next row from the given result object, in associative array form. Fields are
58 * retrieved with $row['fieldname']. If no more rows are available, false is returned.
61 * @throws DBUnexpectedError Thrown if the database returns an error
64 return $this->db
->fetchRow( $this );
68 * Free a result object
71 $this->db
->freeResult( $this );
72 unset( $this->result
);
77 * Change the position of the cursor in a result object.
78 * See mysql_data_seek()
82 function seek( $row ) {
83 $this->db
->dataSeek( $this, $row );
87 * ======= Iterator functions =======
88 * Note that using these in combination with the non-iterator functions
89 * above may cause rows to be skipped or repeated.
93 if ( $this->numRows() ) {
94 $this->db
->dataSeek( $this, 0 );
97 $this->currentRow
= null;
101 * @return stdClass|array|bool
104 if ( is_null( $this->currentRow
) ) {
108 return $this->currentRow
;
123 $this->currentRow
= $this->fetchObject();
125 return $this->currentRow
;
132 return $this->current() !== false;