Friday, December 30, 2011

drupal_write_record

drupal_write_record:

Save a record to the database based upon the schema.
Default values are filled in for missing items, and 'serial' (auto increment) types are filled in with IDs.

Parameters

$table The name of the table; this must exist in schema API.
$object The object to write. This is a reference, as defaults according to the schema may be filled in on the object, as well as ID on the serial type(s). Both array an object types may be passed.
$update If this is an update, specify the primary keys' field names. It is the caller's responsibility to know if a record for this object already exists in the database. If there is only 1 key, you may pass a simple string.

Return value

Failure to write a record will return FALSE. Otherwise SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed. The $object parameter contains values for any serial fields defined by the $table. For example, $object->nid will be populated after inserting a new node.

Example:

$result_array = array_slice($form_state['values'],0,2);
drupal_write_record('tbl_eng_braz',$result_array); 

tbl_eng_braz - table name
$result_array - Sliced array  of the form values to be stored in to the "tbl_eng_braz" table.Only 2 fields are there in the form,so we should create the table with 2 fields and give the name for the fields as per the form.
 

No comments:

Post a Comment