From: Brion Vibber Date: Thu, 2 Sep 2004 02:43:13 +0000 (+0000) Subject: ResultWrapper object, so you can pass a result back as a return value without passing... X-Git-Tag: 1.5.0alpha1~2168 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=d867e6d863143ef8144fe78874c91b5bb4823be3;p=lhc%2Fweb%2Fwiklou.git ResultWrapper object, so you can pass a result back as a return value without passing along the database object you used too. --- 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 #------------------------------------------------------------------------------