Skip to content
Snippets Groups Projects
Commit bca75d35 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #360887 by Crell: more robus example of how to use transaction support in D7.

parent 9e8bfddf
No related branches found
No related tags found
No related merge requests found
......@@ -134,17 +134,27 @@
* // The transaction opens here.
* $txn = db_transaction();
*
* $id = db_insert('example')
* ->fields(array(
* 'field1' => 'mystring',
* 'field2' => 5,
* ))
* ->execute();
* try {
* $id = db_insert('example')
* ->fields(array(
* 'field1' => 'mystring',
* 'field2' => 5,
* ))
* ->execute();
*
* my_other_function($id);
*
* my_other_function($id);
* return $id;
* }
* catch (Exception $e) {
* // Something went wrong somewhere, so flag the entire transaction to
* // roll back instead of getting committed. It doesn't actually roll back
* // yet, just gets flagged to do so.
* $txn->rollback();
* }
*
* return $id;
* // $txn goes out of scope here, and the entire transaction commits.
* // $txn goes out of scope here. If there was a problem, it rolls back
* // automatically. If not, it commits automatically.
* }
*
* function my_other_function($id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment