1 database_example.module | database_example_entry_update($entry) |
Updates an entry in the database.
The former, deprecated techniques used db_query() or backdrop_write_record():
backdrop_write_record('database_example', $entry, $entry['pid']);
db_query(
"UPDATE {database_example}
SET name = '%s', surname = '%s', age = '%d'
WHERE pid = %d",
$entry['pid']
);
Parameters
array $entry: An array containing all the fields of the item to be updated.
See also
Related topics
File
- modules/
examples/ database_example/ database_example.module, line 118 - Hook implementations for the Database Example module.
Code
function database_example_entry_update($entry) {
try {
// db_update()->execute() returns the number of updated rows.
$count = db_update('database_example')
->fields($entry)
->condition('pid', $entry['pid'])
->execute();
}
catch (Exception $e) {
backdrop_set_message(t('db_update failed. Message = %message, query= %query', array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error');
}
return $count;
}