3

How can I get count of deleted rows after db_delete?

db_delete('node')
  ->condition('uid', 1)
  ->execute();

something like

$count = db_delete('node')
  ->condition('uid', 1)
  ->execute()->columnCount();

doesn't work

3 Answers 3

7

The delete query will return a query object for all methods except ->execute(). Methods can be chained until the query has been assembled. Execute() completes the chain.

Try:

$count = db_delete('node')
  ->condition('uid', 1)
  ->execute();
1
  • thanks. yes. the task was simple. Looks I simply had some mistakes in conditions of my query.
    – milkovsky
    Commented Mar 28, 2013 at 17:24
2

You can get count of deleted rows as follow:

db_delete('node')
  ->condition('uid', 1)
  ->execute();

$count = db_query('SELECT ROW_COUNT()')->fetchField();

print($count);
2

Next expression works:

$count= db_delete('node')
  ->condition('uid', 1)
  ->execute();

dpm($count);

db_delete returns count of deleted rows after execution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.