-
Book Overview & Buying
-
Table Of Contents
Drupal 7 First Look
Now that we have looked in depth at the various ways of selecting data using the Drupal 7 DBTNG layer, let's look into the insert queries. Insert queries are used to enter data into the database.
To create an insert statement, you start by calling the db_insert method. The signature of the db_insert method is:
db_insert($table, array $options = array())
The only required parameter is the name of the table you want to insert data into. For example, to create an insert statement for the node table, you would call:
<?php
$query = db_insert('node');
?>After the query has been created, you will need to specify which fields need to be inserted as well as the values for each field. This is done by calling the fields method of the insert query. You can call the fields method with an associative array that contains both the field names and the values for each field, as shown below:
<?php
$query = db_insert('node')
->fields(array(
'title...
Change the font size
Change margin width
Change background colour