function dbtng_example_entry_update

Update an entry in the database.

The former, deprecated techniques used db_query() or drupal_write_record():

drupal_write_record('dbtng_example', $entry, $entry['pid']);
db_query("UPDATE {dbtng_example}\n    SET name = '%s', surname = '%s', age = '%d'\n    WHERE pid = %d", $entry['pid']);

Parameters

array $entry: An array containing all the fields of the item to be updated.

See also

db_update()

Related topics

2 calls to dbtng_example_entry_update()
DBTNGExampleUnitTestCase::testAPIExamples in dbtng_example/dbtng_example.test
Test several combinations, adding entries, updating and deleting.
dbtng_example_form_update_submit in dbtng_example/dbtng_example.module
Submit handler for 'update entry' form.

File

dbtng_example/dbtng_example.module, line 132

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) {
        drupal_set_message(t('db_update failed. Message = %message, query= %query', array(
            '%message' => $e->getMessage(),
            '%query' => $e->query_string,
        )), 'error');
    }
    return $count;
}