From d867e6d863143ef8144fe78874c91b5bb4823be3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 2 Sep 2004 02:43:13 +0000 Subject: [PATCH] ResultWrapper object, so you can pass a result back as a return value without passing along the database object you used too. --- includes/Database.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/includes/Database.php b/includes/Database.php index b9640551ea..49b9039c24 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -949,12 +949,51 @@ class Database { function timestamp( $ts=0 ) { return wfTimestamp(TS_MW,$ts); } + + function &resultObject( &$result ) { + if( empty( $result ) ) { + return NULL; + } else { + return new ResultWrapper( $this, $result ); + } + } } class DatabaseMysql extends Database { # Inherit all } +#------------------------------------------------------------------------------ +# Result wrapper for grabbing data queried by someone else +#------------------------------------------------------------------------------ + +class ResultWrapper { + var $db, $result; + + function ResultWrapper( $database, $result ) { + $this->db =& $database; + $this->result =& $result; + } + + function numRows() { + return $this->db->numRows( $this->result ); + } + + function &fetchObject() { + return $this->db->fetchObject( $this->result ); + } + + function &fetchRow() { + return $this->db->fetchRow( $this->result ); + } + + function free() { + $this->db->freeResult( $this->result ); + unset( $this->result ); + unset( $this->db ); + } +} + #------------------------------------------------------------------------------ # Global functions #------------------------------------------------------------------------------ -- 2.20.1