Changeset 16336
- Timestamp:
- 11/12/2010 10:44:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-db.php
r16321 r16336 126 126 127 127 /** 128 * MySQL result resourceof the last query made129 * 130 * @since 3.1.0131 * @access private 132 * @var resource|null133 */ 134 var $ _mysql_last_result;128 * Results of the last query made 129 * 130 * @since 1.0.0 131 * @access private 132 * @var array|null 133 */ 134 var $last_result; 135 135 136 136 /** … … 1016 1016 */ 1017 1017 function flush() { 1018 if ( is_resource( $this->_mysql_last_result ) ) 1019 mysql_free_result( $this->_mysql_last_result ); 1018 $this->last_result = array(); 1020 1019 $this->col_info = null; 1021 1020 $this->last_query = null; … … 1087 1086 $this->timer_start(); 1088 1087 1089 $this-> _mysql_last_result = @mysql_query( $query, $this->dbh );1088 $this->result = @mysql_query( $query, $this->dbh ); 1090 1089 $this->num_queries++; 1091 1090 … … 1109 1108 } else { 1110 1109 $i = 0; 1111 while ( $i < @mysql_num_fields( $this-> _mysql_last_result ) ) {1112 $this->col_info[$i] = @mysql_fetch_field( $this-> _mysql_last_result );1110 while ( $i < @mysql_num_fields( $this->result ) ) { 1111 $this->col_info[$i] = @mysql_fetch_field( $this->result ); 1113 1112 $i++; 1114 1113 } 1114 $num_rows = 0; 1115 while ( $row = @mysql_fetch_object( $this->result ) ) { 1116 $this->last_result[$num_rows] = $row; 1117 $num_rows++; 1118 } 1119 1120 @mysql_free_result( $this->result ); 1115 1121 1116 1122 // Log number of rows the query returned 1117 1123 // and return number of rows selected 1118 $this->num_rows = @mysql_num_rows( $this->_mysql_last_result );1119 $return_val = $ this->num_rows;1124 $this->num_rows = $num_rows; 1125 $return_val = $num_rows; 1120 1126 } 1121 1127 … … 1276 1282 $this->query( $query ); 1277 1283 1278 // Extract var from result resource based x,y vals 1279 if ( $this->num_rows > $y ) { 1280 @mysql_data_seek( $this->_mysql_last_result, $y ); 1281 $values = @mysql_fetch_row( $this->_mysql_last_result ); 1284 // Extract var out of cached results based x,y vals 1285 if ( !empty( $this->last_result[$y] ) ) { 1286 $values = array_values( get_object_vars( $this->last_result[$y] ) ); 1282 1287 } 1283 1288 … … 1306 1311 return null; 1307 1312 1308 if ( $this->num_rows <= $y)1313 if ( !isset( $this->last_result[$y] ) ) 1309 1314 return null; 1310 1315 1311 @mysql_data_seek( $this->_mysql_last_result, $y );1312 1313 1316 if ( $output == OBJECT ) { 1314 return @mysql_fetch_object( $this->_mysql_last_result );1317 return $this->last_result[$y] ? $this->last_result[$y] : null; 1315 1318 } elseif ( $output == ARRAY_A ) { 1316 return @mysql_fetch_assoc( $this->_mysql_last_result );1319 return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; 1317 1320 } elseif ( $output == ARRAY_N ) { 1318 return @mysql_fetch_row( $this->_mysql_last_result );1321 return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; 1319 1322 } else { 1320 1323 $this->print_error(/*WP_I18N_DB_GETROW_ERROR*/" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"/*/WP_I18N_DB_GETROW_ERROR*/); … … 1341 1344 $new_array = array(); 1342 1345 // Extract the column values 1343 @mysql_data_seek( $this->_mysql_last_result, 0 ); 1344 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1345 $values = @mysql_fetch_row( $this->_mysql_last_result ); 1346 if ( isset( $values[$x] ) && $values[$x] !== '' ) 1347 $new_array[$i] = $values[$x]; 1348 else 1349 $new_array[$i] = null; 1346 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 1347 $new_array[$i] = $this->get_var( null, $x, $i ); 1350 1348 } 1351 1349 return $new_array; … … 1374 1372 1375 1373 $new_array = array(); 1376 @mysql_data_seek( $this->_mysql_last_result, 0 );1377 1374 if ( $output == OBJECT ) { 1378 1375 // Return an integer-keyed array of row objects 1379 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1380 $new_array[] = @mysql_fetch_object( $this->_mysql_last_result ); 1381 } 1382 return $new_array; 1376 return $this->last_result; 1383 1377 } elseif ( $output == OBJECT_K ) { 1384 1378 // Return an array of row objects with keys from column 1 1385 1379 // (Duplicates are discarded) 1386 while ( $row = @mysql_fetch_object( $this->_mysql_last_result )) {1380 foreach ( $this->last_result as $row ) { 1387 1381 $key = array_shift( $var_by_ref = get_object_vars( $row ) ); 1388 1382 if ( ! isset( $new_array[ $key ] ) ) … … 1390 1384 } 1391 1385 return $new_array; 1392 } elseif ( $output == ARRAY_A ) { 1393 // Return an integer-keyed array of column name-keyed row arrays 1394 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1395 $new_array[] = @mysql_fetch_assoc( $this->_mysql_last_result ); 1396 } 1397 return $new_array; 1398 } elseif ( $output == ARRAY_N ) { 1399 // Return an integer-keyed array of integer-keyed row arrays 1400 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1401 $new_array[] = @mysql_fetch_row( $this->_mysql_last_result ); 1386 } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { 1387 // Return an integer-keyed array of... 1388 if ( $this->last_result ) { 1389 foreach( (array) $this->last_result as $row ) { 1390 if ( $output == ARRAY_N ) { 1391 // ...integer-keyed row arrays 1392 $new_array[] = array_values( get_object_vars( $row ) ); 1393 } else { 1394 // ...column name-keyed row arrays 1395 $new_array[] = get_object_vars( $row ); 1396 } 1397 } 1402 1398 } 1403 1399 return $new_array; … … 1564 1560 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 1565 1561 } 1566 1567 /**1568 * Magic getter used for the deprecated last_result property.1569 *1570 * @since 3.1.01571 * @access private1572 */1573 function __get( $name ) {1574 if ( 'last_result' == $name ) {1575 _deprecated_argument( 'wpdb', '3.1', __( 'The last_result property is deprecated. Use $wpdb->get_result().' ) );1576 return $this->get_results();1577 }1578 return null;1579 }1580 1562 } 1581 1563
Note: See TracChangeset
for help on using the changeset viewer.