1 dbtng_example.module | dbtng_example_entry_update($entry) |
Update an entry in the database.
The former, deprecated techniques used db_query() or backdrop_write_record():
backdrop_write_record('dbtng_example', $entry, $entry['pid']);
db_query(
"UPDATE {dbtng_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/ dbtng_example/ dbtng_example.module, line 128 - This is an example outlining how a module can make use of the DBTNG database API in Backdrop.
Code
function dbtng_example_entry_update($entry) {
try {
// db_update()...->execute() returns the number of rows updated.
$count = db_update('dbtng_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;
}