[wp-hackers] $wpdb->query update and the number of records effected.

Otto 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.

http://dev.mysql.com/doc/refman/5.0/en/update.html

"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."

-Otto


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
>
> int(19979)
>
> then I reload the php page again ( to execute same SQL ) and the
> var_dump reports
>
> int(0)
>
> 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
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list