[wp-hackers] $wpdb->query update and the number of records effected.
otto at ottodestruct.com
Fri Feb 8 17:44:53 UTC 2013
On an UPDATE, MySQL will report the number of rows actually changed,
not the possible number of rows affected. If comment_count is already
zero, then your second update makes no change, and so it won't change
it or report that row as changed in the return value.
"If you set a column to the value it currently has, MySQL notices this
and does not update it."
"UPDATE returns the number of rows that were actually changed."
On Fri, Feb 8, 2013 at 11:24 AM, Haluk Karamete <halukkaramete at gmail.com> wrote:
> I run this;
> global $wpdb; //wpdb is the wordpress database class
> var_dump ($wpdb->query( "UPDATE $wpdb->posts SET comment_count=0"));
> And I get this by the var_dump
> then I reload the php page again ( to execute same SQL ) and the
> var_dump reports
> Should not this query always effect 19979 records?
> I thought the number of recs effected is really whatever the where
> scope happens to be covering.
> Since there are 19979 recs in the posts table, I was expecting this
> operation spans/touches/operates/whateveer very you want to call it
> all the recs!
> I guess whether the values in the comment_count field was 0 or not
> seffect the return of the wpdb->query.
> Is this a mySQL behaviour? or does wordpress do something here? Or is
> there somesort of a caching involved?
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers