Skip to content

Instantly share code, notes, and snippets.

@bkrall
Last active July 18, 2016 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkrall/6011872 to your computer and use it in GitHub Desktop.
Save bkrall/6011872 to your computer and use it in GitHub Desktop.
Try/Catch in Drupal
function dbtng_example_entry_insert($entry) {
$return_value = NULL;
try {
$return_value = db_insert('dbtng_example')
->fields($entry)
->execute();
}
catch (Exception $e) {
drupal_set_message(t('db_insert failed. Message = %message, query= %query',
array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error');
}
return $return_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment