-
Book Overview & Buying
-
Table Of Contents
Drupal 7 First Look
If you need to delete a record from a table, you can use a delete query to remove the record. A delete statement is started by calling the db_delete method, which accepts the table to delete from much like the other queries we have looked at. The signature of the db_delete method is:
db_delete($table, array $options = array())
After creating the query, you need to specify the condition that should be used to determine which records should be deleted. You can use any of the condition functions we described earlier while talking about select statements.
Let's look at a simple example that deletes any node that has the word delete in the title.
<?php
$query = db_insert('node')
->condition('title', '%delete%', 'LIKE');
$num_deleted = $query->execute();
?>The execute method for a delete statement will return the number of records that were actually deleted by the query.
Change the font size
Change margin width
Change background colour