diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php
index 5393240..7cdda3d 100644
|
a
|
b
|
class wpdb { |
| 126 | 126 | var $last_query; |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | | * Results of the last query made |
| 130 | | * |
| 131 | | * @since 0.71 |
| 132 | | * @access private |
| 133 | | * @var array|null |
| 134 | | */ |
| 135 | | var $last_result; |
| 136 | | |
| 137 | | /** |
| 138 | 129 | * MySQL result, which is either a resource or boolean. |
| 139 | 130 | * |
| 140 | 131 | * @since 0.71 |
| … |
… |
public function suppress_errors( $suppress = true ) { |
| 1360 | 1351 | * @return void |
| 1361 | 1352 | */ |
| 1362 | 1353 | public function flush() { |
| 1363 | | $this->last_result = array(); |
| 1364 | 1354 | $this->col_info = null; |
| 1365 | 1355 | $this->last_query = null; |
| 1366 | 1356 | $this->rows_affected = $this->num_rows = 0; |
| … |
… |
public function query( $query ) { |
| 1691 | 1681 | } else { |
| 1692 | 1682 | $num_rows = 0; |
| 1693 | 1683 | if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { |
| 1694 | | while ( $row = @mysqli_fetch_object( $this->result ) ) { |
| 1695 | | $this->last_result[$num_rows] = $row; |
| 1696 | | $num_rows++; |
| 1697 | | } |
| | 1684 | $num_rows = @mysql_num_rows( $this->result ); |
| 1698 | 1685 | } elseif ( is_resource( $this->result ) ) { |
| 1699 | | while ( $row = @mysql_fetch_object( $this->result ) ) { |
| 1700 | | $this->last_result[$num_rows] = $row; |
| 1701 | | $num_rows++; |
| 1702 | | } |
| | 1686 | $num_rows = @mysql_num_rows( $this->result ); |
| 1703 | 1687 | } |
| 1704 | 1688 | |
| 1705 | 1689 | // Log number of rows the query returned |
| … |
… |
private function _do_query( $query ) { |
| 1731 | 1715 | } else { |
| 1732 | 1716 | $this->result = @mysql_query( $query, $this->dbh ); |
| 1733 | 1717 | } |
| | 1718 | |
| 1734 | 1719 | $this->num_queries++; |
| 1735 | 1720 | |
| 1736 | 1721 | if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { |
| … |
… |
public function get_var( $query = null, $x = 0, $y = 0 ) { |
| 2043 | 2028 | } |
| 2044 | 2029 | |
| 2045 | 2030 | // Extract var out of cached results based x,y vals |
| 2046 | | if ( !empty( $this->last_result[$y] ) ) { |
| 2047 | | $values = array_values( get_object_vars( $this->last_result[$y] ) ); |
| | 2031 | if ( $y < $this->num_rows ) { |
| | 2032 | if ( $this->use_mysqli ) { |
| | 2033 | @mysqli_data_seek( $this->result, $y ); |
| | 2034 | $values = @mysqli_fetch_row( $this->result ); |
| | 2035 | } else { |
| | 2036 | @mysql_data_seek( $this->result, $y ); |
| | 2037 | $values = @mysql_fetch_row( $this->result ); |
| | 2038 | } |
| 2048 | 2039 | } |
| 2049 | 2040 | |
| 2050 | 2041 | // If there is a value return it else return null |
| … |
… |
public function get_row( $query = null, $output = OBJECT, $y = 0 ) { |
| 2072 | 2063 | return null; |
| 2073 | 2064 | } |
| 2074 | 2065 | |
| 2075 | | if ( !isset( $this->last_result[$y] ) ) |
| | 2066 | if ( $this->num_rows <= $y ) { |
| 2076 | 2067 | return null; |
| | 2068 | } |
| | 2069 | |
| | 2070 | if ( $this->use_mysqli ) { |
| | 2071 | @mysqli_data_seek( $this->result, $y ); |
| | 2072 | } else { |
| | 2073 | @mysql_data_seek( $this->result, $y ); |
| | 2074 | } |
| 2077 | 2075 | |
| 2078 | | if ( $output == OBJECT ) { |
| 2079 | | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| | 2076 | if ( $output == OBJECT || strtoupper( $output ) === OBJECT ) { |
| | 2077 | if ( $this->use_mysqli ) { |
| | 2078 | return @mysqli_fetch_object( $this->result ); |
| | 2079 | } else { |
| | 2080 | return @mysql_fetch_object( $this->result ); |
| | 2081 | } |
| 2080 | 2082 | } elseif ( $output == ARRAY_A ) { |
| 2081 | | return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; |
| | 2083 | if ( $this->use_mysqli ) { |
| | 2084 | return @mysqli_fetch_object( $this->result ); |
| | 2085 | } else { |
| | 2086 | return @mysql_fetch_object( $this->result ); |
| | 2087 | } |
| 2082 | 2088 | } elseif ( $output == ARRAY_N ) { |
| 2083 | | return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; |
| | 2089 | if ( $this->use_mysqli ) { |
| | 2090 | return @mysqli_fetch_assoc( $this->result ); |
| | 2091 | } else { |
| | 2092 | return @mysql_fetch_assoc( $this->result ); |
| | 2093 | } |
| 2084 | 2094 | } elseif ( strtoupper( $output ) === OBJECT ) { |
| 2085 | 2095 | // Back compat for OBJECT being previously case insensitive. |
| 2086 | | return $this->last_result[$y] ? $this->last_result[$y] : null; |
| | 2096 | if ( $this->use_mysqli ) { |
| | 2097 | return @mysqli_fetch_row( $this->result ); |
| | 2098 | } else { |
| | 2099 | return @mysql_fetch_row( $this->result ); |
| | 2100 | } |
| 2087 | 2101 | } else { |
| 2088 | 2102 | $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" ); |
| 2089 | 2103 | } |
| … |
… |
public function get_col( $query = null , $x = 0 ) { |
| 2108 | 2122 | } |
| 2109 | 2123 | |
| 2110 | 2124 | $new_array = array(); |
| | 2125 | |
| | 2126 | @mysql_data_seek( $this->result, 0 ); |
| | 2127 | |
| 2111 | 2128 | // Extract the column values |
| 2112 | | for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { |
| 2113 | | $new_array[$i] = $this->get_var( null, $x, $i ); |
| | 2129 | for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { |
| | 2130 | if ( $this->use_mysqli ) { |
| | 2131 | $values = @mysqli_fetch_row( $this->result ); |
| | 2132 | } else { |
| | 2133 | $values = @mysql_fetch_row( $this->result ); |
| | 2134 | } |
| | 2135 | |
| | 2136 | if ( isset( $values[$x] ) && $values[$x] !== '' ) { |
| | 2137 | $new_array[$i] = $values[$x]; |
| | 2138 | } else { |
| | 2139 | $new_array[$i] = null; |
| | 2140 | } |
| 2114 | 2141 | } |
| | 2142 | |
| 2115 | 2143 | return $new_array; |
| 2116 | 2144 | } |
| 2117 | 2145 | |
| … |
… |
public function get_results( $query = null, $output = OBJECT ) { |
| 2133 | 2161 | |
| 2134 | 2162 | if ( $query ) { |
| 2135 | 2163 | $this->query( $query ); |
| 2136 | | } else { |
| 2137 | | return null; |
| 2138 | 2164 | } |
| | 2165 | |
| | 2166 | @mysql_data_seek( $this->result, 0 ); |
| 2139 | 2167 | |
| 2140 | 2168 | $new_array = array(); |
| 2141 | | if ( $output == OBJECT ) { |
| | 2169 | |
| | 2170 | if ( $output == OBJECT || strtoupper( $output ) === OBJECT ) { |
| 2142 | 2171 | // Return an integer-keyed array of row objects |
| 2143 | | return $this->last_result; |
| | 2172 | for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { |
| | 2173 | if ( $this->use_mysqli ) { |
| | 2174 | $new_array[] = @mysqli_fetch_object( $this->result ); |
| | 2175 | } else { |
| | 2176 | $new_array[] = @mysql_fetch_object( $this->result ); |
| | 2177 | } |
| | 2178 | } |
| | 2179 | |
| | 2180 | return $new_array; |
| 2144 | 2181 | } elseif ( $output == OBJECT_K ) { |
| 2145 | 2182 | // Return an array of row objects with keys from column 1 |
| 2146 | 2183 | // (Duplicates are discarded) |
| 2147 | | foreach ( $this->last_result as $row ) { |
| | 2184 | if ( $this->use_mysqi ) { |
| | 2185 | $row = @mysqli_fetch_object( $this->result ); |
| | 2186 | } else { |
| | 2187 | $row = @mysql_fetch_object( $this->result ); |
| | 2188 | } |
| | 2189 | |
| | 2190 | while ( $row ) { |
| 2148 | 2191 | $var_by_ref = get_object_vars( $row ); |
| 2149 | 2192 | $key = array_shift( $var_by_ref ); |
| 2150 | | if ( ! isset( $new_array[ $key ] ) ) |
| | 2193 | |
| | 2194 | if ( ! isset( $new_array[ $key ] ) ) { |
| 2151 | 2195 | $new_array[ $key ] = $row; |
| | 2196 | } |
| | 2197 | |
| | 2198 | if ( $this->use_mysqi ) { |
| | 2199 | $row = @mysqli_fetch_object( $this->result ); |
| | 2200 | } else { |
| | 2201 | $row = @mysql_fetch_object( $this->result ); |
| | 2202 | } |
| 2152 | 2203 | } |
| | 2204 | |
| 2153 | 2205 | return $new_array; |
| 2154 | | } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { |
| 2155 | | // Return an integer-keyed array of... |
| 2156 | | if ( $this->last_result ) { |
| 2157 | | foreach( (array) $this->last_result as $row ) { |
| 2158 | | if ( $output == ARRAY_N ) { |
| 2159 | | // ...integer-keyed row arrays |
| 2160 | | $new_array[] = array_values( get_object_vars( $row ) ); |
| 2161 | | } else { |
| 2162 | | // ...column name-keyed row arrays |
| 2163 | | $new_array[] = get_object_vars( $row ); |
| 2164 | | } |
| | 2206 | } elseif ( $output == ARRAY_A ) { |
| | 2207 | // Return an integer-keyed array of column name-keyed row arrays |
| | 2208 | for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { |
| | 2209 | if ( $this->use_mysqli ) { |
| | 2210 | $new_array[] = @mysqli_fetch_assoc( $this->result ); |
| | 2211 | } else { |
| | 2212 | $new_array[] = @mysql_fetch_assoc( $this->result ); |
| 2165 | 2213 | } |
| 2166 | 2214 | } |
| | 2215 | |
| | 2216 | return $new_array; |
| | 2217 | } elseif ( $output == ARRAY_N ) { |
| | 2218 | // Return an integer-keyed array of integer-keyed row arrays |
| | 2219 | for ( $i = 0, $j = $this->num_rows; $i < $j; $i++ ) { |
| | 2220 | if ( $this->use_mysqli ) { |
| | 2221 | $new_array[] = @mysqli_fetch_row( $this->result ); |
| | 2222 | } else { |
| | 2223 | $new_array[] = @mysql_fetch_row( $this->result ); |
| | 2224 | } |
| | 2225 | } |
| | 2226 | |
| 2167 | 2227 | return $new_array; |
| 2168 | | } elseif ( strtoupper( $output ) === OBJECT ) { |
| 2169 | | // Back compat for OBJECT being previously case insensitive. |
| 2170 | | return $this->last_result; |
| 2171 | 2228 | } |
| | 2229 | |
| 2172 | 2230 | return null; |
| 2173 | 2231 | } |
| 2174 | 2232 | |