wpdb delete query count

How do you count the number of times a delete query has been successfully executed using wordpress default database class.

for example:

Read More
$delete = $wpdb->query("DELETE FROM table where and itemid > itemid");

I know one way is to fire a select count:

$deletecount = $wpdb->query("SELECT COUNT(*) FROM table where itemid > itemid");

but is there a direct way to know the count without executing a second query?

Thank you!

Related posts

Leave a Reply

1 comment

  1. The $wpdb->query(...) function returns an integer value corresponding to the number of rows affected. So, if you delete 10 rows then it’ll return 10, use it like:

    $count = $wpdb->query('delete query');
    

    Also you may use the delete method:

    $count = $wpdb->delete( $table, $where, $where_format = null );
    

    Returns the same affected rows on successful operation and false on failure. Read more on Codex.