WordPress.org

Make WordPress Core

Ticket #18574: 18574.diff

File 18574.diff, 2.7 KB (added by andy, 22 months ago)
  • wp-includes/wp-db.php

     
    133133        var $last_result; 
    134134 
    135135        /** 
     136         * Name of class to instantiate when fetching rows. 
     137         * Specified in 2nd argument to query(), get_row(), get_results(). 
     138         * @access private 
     139         * @var string|null 
     140         */ 
     141        var $row_class; 
     142 
     143        /** 
    136144         * Saved info on the table column 
    137145         * 
    138146         * @since 1.2.0 
     
    10051013                $this->last_result = array(); 
    10061014                $this->col_info    = null; 
    10071015                $this->last_query  = null; 
     1016                $this->row_class   = null; 
    10081017        } 
    10091018 
    10101019        /** 
     
    10511060         * @param string $query Database query 
    10521061         * @return int|false Number of rows affected/selected or false on error 
    10531062         */ 
    1054         function query( $query ) { 
     1063        function query( $query, $class = null ) { 
    10551064                if ( ! $this->ready ) 
    10561065                        return false; 
    10571066 
     
    10941103                        // Return number of rows affected 
    10951104                        $return_val = $this->rows_affected; 
    10961105                } else { 
     1106                        if ( is_string( $class ) && class_exists( $class ) ) 
     1107                                $this->row_class = $class; 
     1108                        else 
     1109                                $this->row_class = 'stdClass'; 
    10971110                        $i = 0; 
    10981111                        while ( $i < @mysql_num_fields( $this->result ) ) { 
    10991112                                $this->col_info[$i] = @mysql_fetch_field( $this->result ); 
    11001113                                $i++; 
    11011114                        } 
    11021115                        $num_rows = 0; 
    1103                         while ( $row = @mysql_fetch_object( $this->result ) ) { 
     1116                        while ( $row = @mysql_fetch_object( $this->result, $this->row_class ) ) { 
    11041117                                $this->last_result[$num_rows] = $row; 
    11051118                                $num_rows++; 
    11061119                        } 
     
    12941307        function get_row( $query = null, $output = OBJECT, $y = 0 ) { 
    12951308                $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 
    12961309                if ( $query ) 
    1297                         $this->query( $query ); 
     1310                        $this->query( $query, $output ); 
    12981311                else 
    12991312                        return null; 
    13001313 
    13011314                if ( !isset( $this->last_result[$y] ) ) 
    13021315                        return null; 
    13031316 
    1304                 if ( $output == OBJECT ) { 
     1317                if ( $output == OBJECT || $output == $this->row_class ) { 
    13051318                        return $this->last_result[$y] ? $this->last_result[$y] : null; 
    13061319                } elseif ( $output == ARRAY_A ) { 
    13071320                        return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; 
     
    13541367                $this->func_call = "\$db->get_results(\"$query\", $output)"; 
    13551368 
    13561369                if ( $query ) 
    1357                         $this->query( $query ); 
     1370                        $this->query( $query, $output ); 
    13581371                else 
    13591372                        return null; 
    13601373 
    13611374                $new_array = array(); 
    1362                 if ( $output == OBJECT ) { 
     1375                if ( $output == OBJECT || $output == $this->row_class ) { 
    13631376                        // Return an integer-keyed array of row objects 
    13641377                        return $this->last_result; 
    1365                 } elseif ( $output == OBJECT_K ) { 
     1378                } elseif ( $output == OBJECT_K || $output == $this->row_class ) { 
    13661379                        // Return an array of row objects with keys from column 1 
    13671380                        // (Duplicates are discarded) 
    13681381                        foreach ( $this->last_result as $row ) {