2

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

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();
  • thanks. yes. the task was simple. Looks I simply had some mistakes in conditions of my query. – milkovsky Mar 28 '13 at 17:24
2

Next expression works:

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

dpm($count);

db_delete returns count of deleted rows after execution.

1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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