Ticket #12257: wp-db.php.get_result().diff
File wp-db.php.get_result().diff, 5.6 KB (added by , 14 years ago) |
---|
-
wp-db.php
125 125 var $last_query; 126 126 127 127 /** 128 * Resultsof the last query made128 * MySQL result resource of the last query made 129 129 * 130 * @since 1.0.0130 * @since 3.?.? 131 131 * @access private 132 * @var array|null132 * @var resource|null 133 133 */ 134 var $ last_result;134 var $mysql_last_result; 135 135 136 136 /** 137 137 * Saved info on the table column … … 1015 1015 * @return void 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; 1021 1021 } … … 1085 1085 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 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 1091 1091 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) … … 1107 1107 $return_val = $this->rows_affected; 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 1114 1120 @mysql_free_result( $this->result );1121 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 1128 1121 return $return_val; … … 1281 1274 if ( $query ) 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 1289 1283 // If there is a value return it else return null … … 1310 1304 else 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*/); 1324 1320 } … … 1343 1339 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; 1350 1351 } … … 1367 1368 1368 1369 if ( $query ) 1369 1370 $this->query( $query ); 1370 else1371 return null;1372 1371 1373 1372 $new_array = array(); 1373 @mysql_data_seek( $this->mysql_last_result, 0 ); 1374 1374 if ( $output == OBJECT ) { 1375 1375 // Return an integer-keyed array of row objects 1376 return $this->last_result; 1376 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1377 $new_array[] = @mysql_fetch_object( $this->mysql_last_result ); 1378 } 1379 return $new_array; 1377 1380 } elseif ( $output == OBJECT_K ) { 1378 1381 // Return an array of row objects with keys from column 1 1379 1382 // (Duplicates are discarded) 1380 foreach ( $this->last_result as $row) {1383 while ( $row = @mysql_fetch_object( $this->mysql_last_result ) ) { 1381 1384 $key = array_shift( $var_by_ref = get_object_vars( $row ) ); 1382 1385 if ( ! isset( $new_array[ $key ] ) ) 1383 1386 $new_array[ $key ] = $row; 1384 1387 } 1385 1388 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 } 1389 } elseif ( $output == ARRAY_A ) { 1390 // Return an integer-keyed array of column name-keyed row arrays 1391 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1392 $new_array[] = @mysql_fetch_assoc( $this->mysql_last_result ); 1398 1393 } 1399 1394 return $new_array; 1395 } elseif ( $output == ARRAY_N ) { 1396 // Return an integer-keyed array of integer-keyed row arrays 1397 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1398 $new_array[] = @mysql_fetch_row( $this->mysql_last_result ); 1399 } 1400 return $new_array; 1400 1401 } 1401 1402 return null; 1402 1403 } … … 1561 1562 } 1562 1563 } 1563 1564 1565 } 1564 1566 ?>