Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 18627)
+++ wp-includes/wp-db.php	(working copy)
@@ -133,6 +133,14 @@
 	var $last_result;
 
 	/**
+	 * Name of class to instantiate when fetching rows.
+	 * Specified in 2nd argument to query(), get_row(), get_results().
+	 * @access private
+	 * @var string|null
+	 */
+	var $row_class;
+
+	/**
 	 * Saved info on the table column
 	 *
 	 * @since 1.2.0
@@ -1005,6 +1013,7 @@
 		$this->last_result = array();
 		$this->col_info    = null;
 		$this->last_query  = null;
+		$this->row_class   = null;
 	}
 
 	/**
@@ -1051,7 +1060,7 @@
 	 * @param string $query Database query
 	 * @return int|false Number of rows affected/selected or false on error
 	 */
-	function query( $query ) {
+	function query( $query, $class = null ) {
 		if ( ! $this->ready )
 			return false;
 
@@ -1094,13 +1103,17 @@
 			// Return number of rows affected
 			$return_val = $this->rows_affected;
 		} else {
+			if ( is_string( $class ) && class_exists( $class ) )
+				$this->row_class = $class;
+			else
+				$this->row_class = 'stdClass';
 			$i = 0;
 			while ( $i < @mysql_num_fields( $this->result ) ) {
 				$this->col_info[$i] = @mysql_fetch_field( $this->result );
 				$i++;
 			}
 			$num_rows = 0;
-			while ( $row = @mysql_fetch_object( $this->result ) ) {
+			while ( $row = @mysql_fetch_object( $this->result, $this->row_class ) ) {
 				$this->last_result[$num_rows] = $row;
 				$num_rows++;
 			}
@@ -1294,14 +1307,14 @@
 	function get_row( $query = null, $output = OBJECT, $y = 0 ) {
 		$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
 		if ( $query )
-			$this->query( $query );
+			$this->query( $query, $output );
 		else
 			return null;
 
 		if ( !isset( $this->last_result[$y] ) )
 			return null;
 
-		if ( $output == OBJECT ) {
+		if ( $output == OBJECT || $output == $this->row_class ) {
 			return $this->last_result[$y] ? $this->last_result[$y] : null;
 		} elseif ( $output == ARRAY_A ) {
 			return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null;
@@ -1354,15 +1367,15 @@
 		$this->func_call = "\$db->get_results(\"$query\", $output)";
 
 		if ( $query )
-			$this->query( $query );
+			$this->query( $query, $output );
 		else
 			return null;
 
 		$new_array = array();
-		if ( $output == OBJECT ) {
+		if ( $output == OBJECT || $output == $this->row_class ) {
 			// Return an integer-keyed array of row objects
 			return $this->last_result;
-		} elseif ( $output == OBJECT_K ) {
+		} elseif ( $output == OBJECT_K || $output == $this->row_class ) {
 			// Return an array of row objects with keys from column 1
 			// (Duplicates are discarded)
 			foreach ( $this->last_result as $row ) {
