Make WordPress Core

Changeset 16336


Ignore:
Timestamp:
11/12/2010 10:44:16 PM (16 years ago)
Author:
westi
Message:

Revert [16320] and [16321] for now. Breaks things

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-db.php

    r16321 r16336  
    126126
    127127        /**
    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;
     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;
    135135
    136136        /**
     
    10161016         */
    10171017        function flush() {
    1018                 if ( is_resource( $this->_mysql_last_result ) )
    1019                         mysql_free_result( $this->_mysql_last_result );
     1018                $this->last_result = array();
    10201019                $this->col_info    = null;
    10211020                $this->last_query  = null;
     
    10871086                        $this->timer_start();
    10881087
    1089                 $this->_mysql_last_result = @mysql_query( $query, $this->dbh );
     1088                $this->result = @mysql_query( $query, $this->dbh );
    10901089                $this->num_queries++;
    10911090
     
    11091108                } else {
    11101109                        $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 );
    11131112                                $i++;
    11141113                        }
     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 );
    11151121
    11161122                        // Log number of rows the query returned
    11171123                        // 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;
    11201126                }
    11211127
     
    12761282                        $this->query( $query );
    12771283
    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] ) );
    12821287                }
    12831288
     
    13061311                        return null;
    13071312
    1308                 if ( $this->num_rows <= $y )
     1313                if ( !isset( $this->last_result[$y] ) )
    13091314                        return null;
    13101315
    1311                 @mysql_data_seek( $this->_mysql_last_result, $y );
    1312 
    13131316                if ( $output == OBJECT ) {
    1314                         return @mysql_fetch_object( $this->_mysql_last_result );
     1317                        return $this->last_result[$y] ? $this->last_result[$y] : null;
    13151318                } 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;
    13171320                } 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;
    13191322                } else {
    13201323                        $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*/);
     
    13411344                $new_array = array();
    13421345                // 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 );
    13501348                }
    13511349                return $new_array;
     
    13741372
    13751373                $new_array = array();
    1376                 @mysql_data_seek( $this->_mysql_last_result, 0 );
    13771374                if ( $output == OBJECT ) {
    13781375                        // 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;
    13831377                } elseif ( $output == OBJECT_K ) {
    13841378                        // Return an array of row objects with keys from column 1
    13851379                        // (Duplicates are discarded)
    1386                         while ( $row = @mysql_fetch_object( $this->_mysql_last_result ) ) {
     1380                        foreach ( $this->last_result as $row ) {
    13871381                                $key = array_shift( $var_by_ref = get_object_vars( $row ) );
    13881382                                if ( ! isset( $new_array[ $key ] ) )
     
    13901384                        }
    13911385                        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                                }
    14021398                        }
    14031399                        return $new_array;
     
    15641560                return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) );
    15651561        }
    1566 
    1567         /**
    1568          * Magic getter used for the deprecated last_result property.
    1569          *
    1570          * @since 3.1.0
    1571          * @access private
    1572          */
    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         }
    15801562}
    15811563
Note: See TracChangeset for help on using the changeset viewer.