Ticket #12257: wp-db.php.diff
File wp-db.php.diff, 5.5 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 } … … 1078 1078 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1079 1079 $this->timer_start(); 1080 1080 1081 $this-> result = @mysql_query( $query, $this->dbh );1081 $this->mysql_last_result = @mysql_query( $query, $this->dbh ); 1082 1082 $this->num_queries++; 1083 1083 1084 1084 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) … … 1100 1100 $return_val = $this->rows_affected; 1101 1101 } else { 1102 1102 $i = 0; 1103 while ( $i < @mysql_num_fields( $this-> result ) ) {1104 $this->col_info[$i] = @mysql_fetch_field( $this-> result );1103 while ( $i < @mysql_num_fields( $this->mysql_last_result ) ) { 1104 $this->col_info[$i] = @mysql_fetch_field( $this->mysql_last_result ); 1105 1105 $i++; 1106 1106 } 1107 $num_rows = 0;1108 while ( $row = @mysql_fetch_object( $this->result ) ) {1109 $this->last_result[$num_rows] = $row;1110 $num_rows++;1111 }1112 1107 1113 @mysql_free_result( $this->result );1114 1115 1108 // Log number of rows the query returned 1116 1109 // and return number of rows selected 1117 $this->num_rows = $num_rows;1118 $return_val = $ num_rows;1110 $this->num_rows = @mysql_num_rows( $this->mysql_last_result ); 1111 $return_val = $this->num_rows; 1119 1112 } 1120 1113 1121 1114 return $return_val; … … 1274 1267 if ( $query ) 1275 1268 $this->query( $query ); 1276 1269 1277 // Extract var out of cached results based x,y vals 1278 if ( !empty( $this->last_result[$y] ) ) { 1279 $values = array_values( get_object_vars( $this->last_result[$y] ) ); 1270 // Extract var from result resource based x,y vals 1271 if ( $this->num_rows > $y ) { 1272 @mysql_data_seek( $this->mysql_last_result, $y ); 1273 $values = @mysql_fetch_row( $this->mysql_last_result ); 1280 1274 } 1281 1275 1282 1276 // If there is a value return it else return null … … 1303 1297 else 1304 1298 return null; 1305 1299 1306 if ( !isset( $this->last_result[$y] ))1300 if ( $this->num_rows <= $y ) 1307 1301 return null; 1308 1302 1303 @mysql_data_seek( $this->mysql_last_result, $y ); 1304 1309 1305 if ( $output == OBJECT ) { 1310 return $this->last_result[$y] ? $this->last_result[$y] : null;1306 return @mysql_fetch_object( $this->mysql_last_result ); 1311 1307 } elseif ( $output == ARRAY_A ) { 1312 return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null;1308 return @mysql_fetch_assoc( $this->mysql_last_result ); 1313 1309 } elseif ( $output == ARRAY_N ) { 1314 return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;1310 return @mysql_fetch_row( $this->mysql_last_result ); 1315 1311 } else { 1316 1312 $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*/); 1317 1313 } … … 1336 1332 1337 1333 $new_array = array(); 1338 1334 // Extract the column values 1339 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 1340 $new_array[$i] = $this->get_var( null, $x, $i ); 1335 @mysql_data_seek( $this->mysql_last_result, 0 ); 1336 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1337 $values = @mysql_fetch_row( $this->mysql_last_result ); 1338 if ( isset( $values[$x] ) && $values[$x] !== '' ) 1339 $new_array[$i] = $values[$x]; 1340 else 1341 $new_array[$i] = null; 1341 1342 } 1342 1343 return $new_array; 1343 1344 } … … 1363 1364 else 1364 1365 return null; 1365 1366 1367 if ( $this->num_rows == 0 ) 1368 return null; 1369 1366 1370 $new_array = array(); 1371 @mysql_data_seek( $this->mysql_last_result, 0 ); 1367 1372 if ( $output == OBJECT ) { 1368 1373 // Return an integer-keyed array of row objects 1369 return $this->last_result; 1374 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1375 $new_array[] = @mysql_fetch_object( $this->mysql_last_result ); 1376 } 1370 1377 } elseif ( $output == OBJECT_K ) { 1371 1378 // Return an array of row objects with keys from column 1 1372 1379 // (Duplicates are discarded) 1373 foreach ( $this->last_result as $row) {1380 while ( $row = @mysql_fetch_object( $this->mysql_last_result ) ) { 1374 1381 $key = array_shift( $var_by_ref = get_object_vars( $row ) ); 1375 1382 if ( ! isset( $new_array[ $key ] ) ) 1376 1383 $new_array[ $key ] = $row; 1377 1384 } 1378 return $new_array; 1379 } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { 1380 // Return an integer-keyed array of... 1381 if ( $this->last_result ) { 1382 foreach( (array) $this->last_result as $row ) { 1383 if ( $output == ARRAY_N ) { 1384 // ...integer-keyed row arrays 1385 $new_array[] = array_values( get_object_vars( $row ) ); 1386 } else { 1387 // ...column name-keyed row arrays 1388 $new_array[] = get_object_vars( $row ); 1389 } 1390 } 1385 } elseif ( $output == ARRAY_A ) { 1386 // Return an integer-keyed array of column name-keyed row arrays 1387 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1388 $new_array[] = @mysql_fetch_assoc( $this->mysql_last_result ); 1391 1389 } 1392 return $new_array; 1390 } elseif ( $output == ARRAY_N ) { 1391 // Return an integer-keyed array of integer-keyed row arrays 1392 for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { 1393 $new_array[] = @mysql_fetch_row( $this->mysql_last_result ); 1394 } 1393 1395 } 1394 return null; 1396 1397 return $new_array; 1395 1398 } 1396 1399 1397 1400 /**