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