MediaWiki REL1_31
MssqlResultWrapper.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use stdClass;
6
9 private $seekTo = null;
10
14 public function fetchObject() {
16
17 if ( $this->seekTo !== null ) {
18 $result = sqlsrv_fetch_object( $res, stdClass::class, [],
19 SQLSRV_SCROLL_ABSOLUTE, $this->seekTo );
20 $this->seekTo = null;
21 } else {
22 $result = sqlsrv_fetch_object( $res );
23 }
24
25 // Return boolean false when there are no more rows instead of null
26 if ( $result === null ) {
27 return false;
28 }
29
30 return $result;
31 }
32
36 public function fetchRow() {
38
39 if ( $this->seekTo !== null ) {
40 $result = sqlsrv_fetch_array( $res, SQLSRV_FETCH_BOTH,
41 SQLSRV_SCROLL_ABSOLUTE, $this->seekTo );
42 $this->seekTo = null;
43 } else {
44 $result = sqlsrv_fetch_array( $res );
45 }
46
47 // Return boolean false when there are no more rows instead of null
48 if ( $result === null ) {
49 return false;
50 }
51
52 return $result;
53 }
54
59 public function seek( $row ) {
61
62 // check bounds
63 $numRows = $this->db->numRows( $res );
64 $row = intval( $row );
65
66 if ( $numRows === 0 ) {
67 return false;
68 } elseif ( $row < 0 || $row > $numRows - 1 ) {
69 return false;
70 }
71
72 // Unlike MySQL, the seek actually happens on the next access
73 $this->seekTo = $row;
74 return true;
75 }
76}
Result wrapper for grabbing data queried from an IDatabase object.
resource array null $result
Optional underlying result handle for subclass usage.
$res
Definition database.txt:21