How do you count the number of times a delete query has been successfully executed using wordpress default database class.
for example:
$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!
The
$wpdb->query(...)
function returns an integer value corresponding to the number of rows affected. So, if you delete10
rows then it’ll return10
, use it like:Also you may use the
delete
method:Returns the same affected rows on successful operation and false on failure. Read more on Codex.