-
Book Overview & Buying
-
Table Of Contents
Drupal 7 First Look
The update statement works similarly to the insert statement with some differences. You create an update statement by calling the db_update method. The db_update method has the following syntax:
db_update($table, array $options = array())
After you create the update statement, you will need to provide the fields that need to be updated as well as the new values for the fields. To specify the fields and values, you will call the fields method and pass an associative array to the method containing the field names and the new values for each field. You will also need to provide the conditions that records must match to be updated. To specify the conditions, you can use any of the functionality used in the select statements to build the conditions for the query.
Let's look at an example that updates the owner of all nodes to user 1 if the title of the node contains the word admin in it:
<?php
$query = db_insert('node')
->fields(array(
'uid' => 1
))
->...
Change the font size
Change margin width
Change background colour