Drupal - Remove Block Directly From Database - Drupal 7

To delete a block programmatically using the Database API, try this:

$module = 'block';
$delta = 1;

// Get the block id (bid) required to delete the correct block from table 'block_custom'
$result = db_select('block', 'b')
         ->fields('b', array('bid'))
         ->condition('module', $module)
         ->condition('delta', $delta)
         ->execute();
$bid = $result->fetchField();

db_delete('block_custom')
  ->condition('bid', $bid)
  ->execute();

db_delete('block')
  ->condition('module', $module)
  ->condition('delta', $delta)
  ->execute();

db_delete('block_role')
  ->condition('module', $module)
  ->condition('delta', $delta)
  ->execute();

When creating custom blocks through the Drupal Block UI, the module name is block and the delta value is an integer. Be sure to use the correct delta value to delete the desired block.


  • Login into PHPMy Admin with admin credentials
  • Search for the block table; in this table search for the block which you have created
  • Change the value of status column form 1 to 0
  • Delete all the content from the cache_bootstrap table

just use this simple query to delete the block.

delete from block where module = 'MODULE' and title = 'TITLE'

Replace MODULE with the name of the module creating the block, and TITLE with the block title.

If the block doesn't have a title, you could use only delete from block where module = 'MODULE'.

Tags:

Database

7

Blocks