Merge "Use gendered pronouns in emailuserfooter"
[mediawiki.git] / includes / libs / rdbms / database / resultwrapper / IResultWrapper.php
blob780f443126fc3194fe55d6c726c3edff171175b3
1 <?php
3 namespace Wikimedia\Rdbms;
5 use Countable;
6 use OutOfBoundsException;
7 use SeekableIterator;
8 use stdClass;
10 /**
11 * Result wrapper for grabbing data queried from an IDatabase object
13 * Note that using the Iterator methods in combination with the non-Iterator
14 * DB result iteration functions may cause rows to be skipped or repeated.
16 * By default, this will use the iteration methods of the IDatabase handle if provided.
17 * Subclasses can override methods to make it solely work on the result resource instead.
18 * If no database is provided, and the subclass does not override the DB iteration methods,
19 * then a RuntimeException will be thrown when iteration is attempted.
21 * The result resource field should not be accessed from non-Database related classes.
22 * It is database class specific and is stored here to associate iterators with queries.
24 * @ingroup Database
26 interface IResultWrapper extends Countable, SeekableIterator {
27 /**
28 * Get the number of rows in a result object
30 * @return int
32 public function numRows();
34 /**
35 * Get the number of rows in a result object
37 * @return int
39 public function count(): int;
41 /**
42 * Fetch the next row from the given result object, in object form. Fields can be retrieved with
43 * $row->fieldname, with fields acting like member variables. If no more rows are available,
44 * false is returned.
46 * @return stdClass|false
47 * @throws DBUnexpectedError Thrown if the database returns an error
49 public function fetchObject();
51 /**
52 * Fetch the next row from the given result object, in associative array form. Fields are
53 * retrieved with $row['fieldname']. If no more rows are available, false is returned.
55 * @return array|false
56 * @throws DBUnexpectedError Thrown if the database returns an error
58 public function fetchRow();
60 /**
61 * Change the position of the cursor in a result object.
62 * See mysql_data_seek()
64 * @throws OutOfBoundsException
65 * @param int $pos
67 public function seek( $pos ): void;
69 /**
70 * Free a result object
72 * This either saves memory in PHP (buffered queries) or on the server (unbuffered queries).
73 * In general, queries are not large enough in result sets for this to be worth calling.
75 public function free();
77 /**
78 * @return stdClass|array|false
80 #[\ReturnTypeWillChange]
81 public function current();
83 /**
84 * @return int
86 public function key(): int;
88 /**
89 * @return void
91 public function next(): void;
93 /**
94 * Get the names of the fields in the result
96 * @since 1.37
97 * @return string[]
99 public function getFieldNames();