function drush_db_delete

8.0.x dbtng.inc drush_db_delete($table, $where = NULL, $args = NULL)
6.x dbtng.inc drush_db_delete($table, $where = NULL, $args = NULL)
7.x dbtng.inc drush_db_delete($table, $where = NULL, $args = NULL)
3.x drush.inc drush_db_delete($table, $where = NULL, $args = NULL)
4.x drush.inc drush_db_delete($table, $where = NULL, $args = NULL)
5.x dbtng.inc drush_db_delete($table, $where = NULL, $args = NULL)
master dbtng.inc drush_db_delete($table, $where = NULL, $args = NULL)

A db_delete() that works for any version of Drupal.

Parameters

$table: String. The table to operate on.

$where: String. WHERE snippet for the operation. It uses named placeholders. see @_drush_replace_query_placeholders()

$args: Array. Arguments for the WHERE snippet.

Return value

Affected rows (except on D7+mysql without a WHERE clause - returns TRUE) or FALSE.

Related topics

1 call to drush_db_delete()
drush_core_watchdog_delete in commands/core/watchdog.drush.inc
Command callback.

File

includes/dbtng.inc, line 143
Wrappers to abstract database operations from Drupal version.

Code

function drush_db_delete($table, $where = NULL, $args = NULL) {
  if (drush_drupal_major_version() >= 7) {
    if (!empty($where)) {
      $query = db_delete($table)->where($where, $args);
      return $query->execute();
    }
    else {
      return db_truncate($table)->execute();
    }
  }
  else {
    $query = "DELETE FROM {{$table}}";
    if (!empty($where)) {
      $where = _drush_replace_query_placeholders($where, $args);
      $query .= ' WHERE ' . $where;
    }
    if (!db_query($query, $args)) {
      return FALSE;
    }
    return db_affected_rows();
  }
}