Ticket #18574: 18574.diff
| File 18574.diff, 2.7 KB (added by andy, 22 months ago) |
|---|
-
wp-includes/wp-db.php
133 133 var $last_result; 134 134 135 135 /** 136 * Name of class to instantiate when fetching rows. 137 * Specified in 2nd argument to query(), get_row(), get_results(). 138 * @access private 139 * @var string|null 140 */ 141 var $row_class; 142 143 /** 136 144 * Saved info on the table column 137 145 * 138 146 * @since 1.2.0 … … 1005 1013 $this->last_result = array(); 1006 1014 $this->col_info = null; 1007 1015 $this->last_query = null; 1016 $this->row_class = null; 1008 1017 } 1009 1018 1010 1019 /** … … 1051 1060 * @param string $query Database query 1052 1061 * @return int|false Number of rows affected/selected or false on error 1053 1062 */ 1054 function query( $query ) {1063 function query( $query, $class = null ) { 1055 1064 if ( ! $this->ready ) 1056 1065 return false; 1057 1066 … … 1094 1103 // Return number of rows affected 1095 1104 $return_val = $this->rows_affected; 1096 1105 } else { 1106 if ( is_string( $class ) && class_exists( $class ) ) 1107 $this->row_class = $class; 1108 else 1109 $this->row_class = 'stdClass'; 1097 1110 $i = 0; 1098 1111 while ( $i < @mysql_num_fields( $this->result ) ) { 1099 1112 $this->col_info[$i] = @mysql_fetch_field( $this->result ); 1100 1113 $i++; 1101 1114 } 1102 1115 $num_rows = 0; 1103 while ( $row = @mysql_fetch_object( $this->result ) ) {1116 while ( $row = @mysql_fetch_object( $this->result, $this->row_class ) ) { 1104 1117 $this->last_result[$num_rows] = $row; 1105 1118 $num_rows++; 1106 1119 } … … 1294 1307 function get_row( $query = null, $output = OBJECT, $y = 0 ) { 1295 1308 $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 1296 1309 if ( $query ) 1297 $this->query( $query );1310 $this->query( $query, $output ); 1298 1311 else 1299 1312 return null; 1300 1313 1301 1314 if ( !isset( $this->last_result[$y] ) ) 1302 1315 return null; 1303 1316 1304 if ( $output == OBJECT ) {1317 if ( $output == OBJECT || $output == $this->row_class ) { 1305 1318 return $this->last_result[$y] ? $this->last_result[$y] : null; 1306 1319 } elseif ( $output == ARRAY_A ) { 1307 1320 return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; … … 1354 1367 $this->func_call = "\$db->get_results(\"$query\", $output)"; 1355 1368 1356 1369 if ( $query ) 1357 $this->query( $query );1370 $this->query( $query, $output ); 1358 1371 else 1359 1372 return null; 1360 1373 1361 1374 $new_array = array(); 1362 if ( $output == OBJECT ) {1375 if ( $output == OBJECT || $output == $this->row_class ) { 1363 1376 // Return an integer-keyed array of row objects 1364 1377 return $this->last_result; 1365 } elseif ( $output == OBJECT_K ) {1378 } elseif ( $output == OBJECT_K || $output == $this->row_class ) { 1366 1379 // Return an array of row objects with keys from column 1 1367 1380 // (Duplicates are discarded) 1368 1381 foreach ( $this->last_result as $row ) {