MediaWiki  master
Wikimedia\Rdbms\ResultWrapper Class Reference

Result wrapper for grabbing data queried from an IDatabase object. More...

Inheritance diagram for Wikimedia\Rdbms\ResultWrapper:
Collaboration diagram for Wikimedia\Rdbms\ResultWrapper:

Public Member Functions

 __construct (IDatabase $db, $result)
 
 current ()
 
 fetchObject ()
 Fetch the next row from the given result object, in object form. More...
 
 fetchRow ()
 Fetch the next row from the given result object, in associative array form. More...
 
 free ()
 Free a result object. More...
 
 key ()
 
 next ()
 
 numRows ()
 Get the number of rows in a result object. More...
 
 rewind ()
 
 seek ( $pos)
 Change the position of the cursor in a result object. More...
 
 valid ()
 

Static Public Member Functions

static & unwrap (&$res)
 Get the underlying RDBMS driver-specific result resource. More...
 

Protected Attributes

stdClass bool null $currentRow
 
IDatabase $db
 
int $pos = 0
 
mixed null $result
 RDBMS driver-specific result resource. More...
 

Private Member Functions

 getDB ()
 

Detailed Description

Result wrapper for grabbing data queried from an IDatabase object.

Only IDatabase-related classes should construct these. Other code may use the FakeResultWrapper class for convenience or compatibility shims.

Note that using the Iterator methods in combination with the non-Iterator IDatabase result iteration functions may cause rows to be skipped or repeated.

By default, this will use the iteration methods of the IDatabase handle if provided. Subclasses can override methods to make it solely work on the result resource instead.

Definition at line 23 of file ResultWrapper.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\ResultWrapper::__construct ( IDatabase  $db,
  $result 
)
Parameters
IDatabase$dbDatabase handle that the result comes from
self | mixed$resultRDBMS driver-specific result resource

Definition at line 38 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$db, and Wikimedia\Rdbms\ResultWrapper\$result.

Member Function Documentation

◆ current()

Wikimedia\Rdbms\ResultWrapper::current ( )

◆ fetchObject()

Wikimedia\Rdbms\ResultWrapper::fetchObject ( )

Fetch the next row from the given result object, in object form.

Fields can be retrieved with $row->fieldname, with fields acting like member variables. If no more rows are available, false is returned.

Returns
stdClass|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 75 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\getDB().

Referenced by Wikimedia\Rdbms\ResultWrapper\current(), and Wikimedia\Rdbms\ResultWrapper\next().

◆ fetchRow()

Wikimedia\Rdbms\ResultWrapper::fetchRow ( )

Fetch the next row from the given result object, in associative array form.

Fields are retrieved with $row['fieldname']. If no more rows are available, false is returned.

Returns
array|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 79 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\getDB().

◆ free()

Wikimedia\Rdbms\ResultWrapper::free ( )

Free a result object.

This either saves memory in PHP (buffered queries) or on the server (unbuffered queries). In general, queries are not large enough in result sets for this to be worth calling.

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 88 of file ResultWrapper.php.

◆ getDB()

◆ key()

Wikimedia\Rdbms\ResultWrapper::key ( )
Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 109 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$pos.

◆ next()

Wikimedia\Rdbms\ResultWrapper::next ( )
Returns
stdClass PhanParamSignatureMismatchInternal

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 113 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$currentRow, and Wikimedia\Rdbms\ResultWrapper\fetchObject().

◆ numRows()

Wikimedia\Rdbms\ResultWrapper::numRows ( )

Get the number of rows in a result object.

Returns
int

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 71 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\getDB().

Referenced by Wikimedia\Rdbms\ResultWrapper\rewind().

◆ rewind()

Wikimedia\Rdbms\ResultWrapper::rewind ( )

◆ seek()

Wikimedia\Rdbms\ResultWrapper::seek (   $pos)

Change the position of the cursor in a result object.

See mysql_data_seek()

Parameters
int$pos

Implements Wikimedia\Rdbms\IResultWrapper.

Definition at line 83 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\$pos, and Wikimedia\Rdbms\ResultWrapper\getDB().

◆ unwrap()

static& Wikimedia\Rdbms\ResultWrapper::unwrap ( $res)
static

◆ valid()

Wikimedia\Rdbms\ResultWrapper::valid ( )

Definition at line 120 of file ResultWrapper.php.

References Wikimedia\Rdbms\ResultWrapper\current().

Member Data Documentation

◆ $currentRow

stdClass bool null Wikimedia\Rdbms\ResultWrapper::$currentRow
protected

◆ $db

IDatabase Wikimedia\Rdbms\ResultWrapper::$db
protected

◆ $pos

int Wikimedia\Rdbms\ResultWrapper::$pos = 0
protected

◆ $result

mixed null Wikimedia\Rdbms\ResultWrapper::$result
protected

RDBMS driver-specific result resource.

Definition at line 27 of file ResultWrapper.php.

Referenced by Wikimedia\Rdbms\ResultWrapper\__construct().


The documentation for this class was generated from the following file: