1 database_example.module database_example_entry_insert($entry)

Saves an entry in the database using db_insert().

In Drupal 6, this would have been:

    "INSERT INTO {database_example} (name, surname, age)
      VALUES ('%s', '%s', '%d')",

Exception handling is shown in this example. It could be simplified without the try/catch blocks, but since an insert will throw an exception and terminate your application if the exception is not handled, it is best to employ try/catch.


array $entry: An array containing all the fields of the database record.

See also


Related topics


modules/examples/database_example/database_example.module, line 81
Hook implementations for the Database Example module.


function database_example_entry_insert($entry) {
  $return_value = NULL;

  try {
    $return_value = db_insert('database_example')
  catch (Exception $e) {
    backdrop_set_message(t('db_insert() failed. Message = %message, query = %query', array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error');

  return $return_value;