<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[16336] trunk/wp-includes/wp-db.php: Revert [16320] and [16321] for now.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16336">16336</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2010-11-12 22:44:16 +0000 (Fri, 12 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revert <a href="http://trac.wordpress.org/changeset/16320">[16320]</a> and <a href="http://trac.wordpress.org/changeset/16321">[16321]</a> for now. Breaks things</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludeswpdbphp">trunk/wp-includes/wp-db.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludeswpdbphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/wp-db.php (16335 => 16336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/wp-db.php        2010-11-12 22:44:08 UTC (rev 16335)
+++ trunk/wp-includes/wp-db.php        2010-11-12 22:44:16 UTC (rev 16336)
</span><span class="lines">@@ -125,13 +125,13 @@
</span><span class="cx">         var $last_query;
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * MySQL result resource of the last query made
</del><ins>+         * Results of the last query made
</ins><span class="cx">          *
</span><del>-         * @since 3.1.0
</del><ins>+         * @since 1.0.0
</ins><span class="cx">          * @access private
</span><del>-         * @var resource|null
</del><ins>+         * @var array|null
</ins><span class="cx">          */
</span><del>-        var $_mysql_last_result;
</del><ins>+        var $last_result;
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * Saved info on the table column
</span><span class="lines">@@ -1015,8 +1015,7 @@
</span><span class="cx">          * @return void
</span><span class="cx">          */
</span><span class="cx">         function flush() {
</span><del>-                if ( is_resource( $this-&gt;_mysql_last_result ) )
-                        mysql_free_result( $this-&gt;_mysql_last_result );
</del><ins>+                $this-&gt;last_result = array();
</ins><span class="cx">                 $this-&gt;col_info    = null;
</span><span class="cx">                 $this-&gt;last_query  = null;
</span><span class="cx">         }
</span><span class="lines">@@ -1086,7 +1085,7 @@
</span><span class="cx">                 if ( defined( 'SAVEQUERIES' ) &amp;&amp; SAVEQUERIES )
</span><span class="cx">                         $this-&gt;timer_start();
</span><span class="cx"> 
</span><del>-                $this-&gt;_mysql_last_result = @mysql_query( $query, $this-&gt;dbh );
</del><ins>+                $this-&gt;result = @mysql_query( $query, $this-&gt;dbh );
</ins><span class="cx">                 $this-&gt;num_queries++;
</span><span class="cx"> 
</span><span class="cx">                 if ( defined( 'SAVEQUERIES' ) &amp;&amp; SAVEQUERIES )
</span><span class="lines">@@ -1108,15 +1107,22 @@
</span><span class="cx">                         $return_val = $this-&gt;rows_affected;
</span><span class="cx">                 } else {
</span><span class="cx">                         $i = 0;
</span><del>-                        while ( $i &lt; @mysql_num_fields( $this-&gt;_mysql_last_result ) ) {
-                                $this-&gt;col_info[$i] = @mysql_fetch_field( $this-&gt;_mysql_last_result );
</del><ins>+                        while ( $i &lt; @mysql_num_fields( $this-&gt;result ) ) {
+                                $this-&gt;col_info[$i] = @mysql_fetch_field( $this-&gt;result );
</ins><span class="cx">                                 $i++;
</span><span class="cx">                         }
</span><ins>+                        $num_rows = 0;
+                        while ( $row = @mysql_fetch_object( $this-&gt;result ) ) {
+                                $this-&gt;last_result[$num_rows] = $row;
+                                $num_rows++;
+                        }
</ins><span class="cx"> 
</span><ins>+                        @mysql_free_result( $this-&gt;result );
+
</ins><span class="cx">                         // Log number of rows the query returned
</span><span class="cx">                         // and return number of rows selected
</span><del>-                        $this-&gt;num_rows = @mysql_num_rows( $this-&gt;_mysql_last_result );
-                        $return_val     = $this-&gt;num_rows;
</del><ins>+                        $this-&gt;num_rows = $num_rows;
+                        $return_val     = $num_rows;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 return $return_val;
</span><span class="lines">@@ -1275,10 +1281,9 @@
</span><span class="cx">                 if ( $query )
</span><span class="cx">                         $this-&gt;query( $query );
</span><span class="cx"> 
</span><del>-                // Extract var from result resource based x,y vals
-                if ( $this-&gt;num_rows &gt; $y ) {
-                        @mysql_data_seek( $this-&gt;_mysql_last_result, $y );
-                        $values = @mysql_fetch_row( $this-&gt;_mysql_last_result );
</del><ins>+                // Extract var out of cached results based x,y vals
+                if ( !empty( $this-&gt;last_result[$y] ) ) {
+                        $values = array_values( get_object_vars( $this-&gt;last_result[$y] ) );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // If there is a value return it else return null
</span><span class="lines">@@ -1305,17 +1310,15 @@
</span><span class="cx">                 else
</span><span class="cx">                         return null;
</span><span class="cx"> 
</span><del>-                if ( $this-&gt;num_rows &lt;= $y )
</del><ins>+                if ( !isset( $this-&gt;last_result[$y] ) )
</ins><span class="cx">                         return null;
</span><span class="cx"> 
</span><del>-                @mysql_data_seek( $this-&gt;_mysql_last_result, $y );
-
</del><span class="cx">                 if ( $output == OBJECT ) {
</span><del>-                        return @mysql_fetch_object( $this-&gt;_mysql_last_result );
</del><ins>+                        return $this-&gt;last_result[$y] ? $this-&gt;last_result[$y] : null;
</ins><span class="cx">                 } elseif ( $output == ARRAY_A ) {
</span><del>-                        return @mysql_fetch_assoc( $this-&gt;_mysql_last_result );
</del><ins>+                        return $this-&gt;last_result[$y] ? get_object_vars( $this-&gt;last_result[$y] ) : null;
</ins><span class="cx">                 } elseif ( $output == ARRAY_N ) {
</span><del>-                        return @mysql_fetch_row( $this-&gt;_mysql_last_result );
</del><ins>+                        return $this-&gt;last_result[$y] ? array_values( get_object_vars( $this-&gt;last_result[$y] ) ) : null;
</ins><span class="cx">                 } else {
</span><span class="cx">                         $this-&gt;print_error(/*WP_I18N_DB_GETROW_ERROR*/&quot; \$db-&gt;get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N&quot;/*/WP_I18N_DB_GETROW_ERROR*/);
</span><span class="cx">                 }
</span><span class="lines">@@ -1340,13 +1343,8 @@
</span><span class="cx"> 
</span><span class="cx">                 $new_array = array();
</span><span class="cx">                 // Extract the column values
</span><del>-                @mysql_data_seek( $this-&gt;_mysql_last_result, 0 );
-                for ( $i = 0, $j = $this-&gt;num_rows; $i &lt; $j; $i++ ) {
-                        $values = @mysql_fetch_row( $this-&gt;_mysql_last_result );
-                        if ( isset( $values[$x] ) &amp;&amp; $values[$x] !== '' )
-                                $new_array[$i] = $values[$x];
-                        else
-                                $new_array[$i] = null;                        
</del><ins>+                for ( $i = 0, $j = count( $this-&gt;last_result ); $i &lt; $j; $i++ ) {
+                        $new_array[$i] = $this-&gt;get_var( null, $x, $i );
</ins><span class="cx">                 }
</span><span class="cx">                 return $new_array;
</span><span class="cx">         }
</span><span class="lines">@@ -1373,34 +1371,32 @@
</span><span class="cx">                         return null;
</span><span class="cx"> 
</span><span class="cx">                 $new_array = array();
</span><del>-                @mysql_data_seek( $this-&gt;_mysql_last_result, 0 );
</del><span class="cx">                 if ( $output == OBJECT ) {
</span><span class="cx">                         // Return an integer-keyed array of row objects
</span><del>-                        for ( $i = 0, $j = $this-&gt;num_rows; $i &lt; $j; $i++ ) {
-                                $new_array[] = @mysql_fetch_object( $this-&gt;_mysql_last_result );
-                        }
-                        return $new_array;
</del><ins>+                        return $this-&gt;last_result;
</ins><span class="cx">                 } elseif ( $output == OBJECT_K ) {
</span><span class="cx">                         // Return an array of row objects with keys from column 1
</span><span class="cx">                         // (Duplicates are discarded)
</span><del>-                        while ( $row = @mysql_fetch_object( $this-&gt;_mysql_last_result ) ) {
</del><ins>+                        foreach ( $this-&gt;last_result as $row ) {
</ins><span class="cx">                                 $key = array_shift( $var_by_ref = get_object_vars( $row ) );
</span><span class="cx">                                 if ( ! isset( $new_array[ $key ] ) )
</span><span class="cx">                                         $new_array[ $key ] = $row;
</span><span class="cx">                         }
</span><span class="cx">                         return $new_array;
</span><del>-                } elseif ( $output == ARRAY_A ) {
-                        // Return an integer-keyed array of column name-keyed row arrays
-                        for ( $i = 0, $j = $this-&gt;num_rows; $i &lt; $j; $i++ ) {
-                                $new_array[] = @mysql_fetch_assoc( $this-&gt;_mysql_last_result );
</del><ins>+                } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
+                        // Return an integer-keyed array of...
+                        if ( $this-&gt;last_result ) {
+                                foreach( (array) $this-&gt;last_result as $row ) {
+                                        if ( $output == ARRAY_N ) {
+                                                // ...integer-keyed row arrays
+                                                $new_array[] = array_values( get_object_vars( $row ) );
+                                        } else {
+                                                // ...column name-keyed row arrays
+                                                $new_array[] = get_object_vars( $row );
+                                        }
+                                }
</ins><span class="cx">                         }
</span><span class="cx">                         return $new_array;
</span><del>-                } elseif ( $output == ARRAY_N ) {
-                        // Return an integer-keyed array of integer-keyed row arrays
-                        for ( $i = 0, $j = $this-&gt;num_rows; $i &lt; $j; $i++ ) {
-                                $new_array[] = @mysql_fetch_row( $this-&gt;_mysql_last_result );
-                        }
-                        return $new_array;
</del><span class="cx">                 }
</span><span class="cx">                 return null;
</span><span class="cx">         }
</span><span class="lines">@@ -1563,20 +1559,6 @@
</span><span class="cx">         function db_version() {
</span><span class="cx">                 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this-&gt;dbh ) );
</span><span class="cx">         }
</span><del>-
-        /**
-         * Magic getter used for the deprecated last_result property.
-         *
-         * @since 3.1.0
-         * @access private
-         */
-        function __get( $name ) {
-                if ( 'last_result' == $name ) {
-                        _deprecated_argument( 'wpdb', '3.1', __( 'The last_result property is deprecated. Use $wpdb-&gt;get_result().' ) );
-                        return $this-&gt;get_results();
-                }
-                return null;
-        }
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>