[wp-hackers] $wpdb->query update and the number of records effected.
Mike Little
wordpress at zed1.com
Fri Feb 8 17:43:07 UTC 2013
On 8 February 2013 17:24, 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?
>
>
The query call is returning the number of rows modified.
If the query results in no modifications (because you already ran it and
changed the data) then you will get 0 returned;
If you use a tool like phpmyadmin you might see the message "19979 rows
affected, 0 rows updated", which makes it clearer.
It is a MySQL efficiency.
Mike
--
Mike Little
http://zed1.com/
More information about the wp-hackers
mailing list