summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database/transactions.rst
diff options
context:
space:
mode:
authorGreg Aker <greg@gregaker.net>2011-10-07 05:22:48 +0200
committerGreg Aker <greg@gregaker.net>2011-10-07 05:22:48 +0200
commit02db0666a8b4da6a58db0e2f6755143ce1b21971 (patch)
tree5f001704bb6a119693e40675a4951db6d462988e /user_guide_src/source/database/transactions.rst
parent4c5dfdfb57fdbda43c79333fa5b3442f1f6c0629 (diff)
parentf24f404a34081241c1398f568b506e2c9d9bec5b (diff)
Merge branch 'user_guide' of https://github.com/jwensley2/CodeIgniter into jwensley2-user_guide
Conflicts: user_guide_src/source/database/configuration.rst
Diffstat (limited to 'user_guide_src/source/database/transactions.rst')
-rw-r--r--user_guide_src/source/database/transactions.rst41
1 files changed, 36 insertions, 5 deletions
diff --git a/user_guide_src/source/database/transactions.rst b/user_guide_src/source/database/transactions.rst
index e82210b96..e9190e59a 100644
--- a/user_guide_src/source/database/transactions.rst
+++ b/user_guide_src/source/database/transactions.rst
@@ -35,7 +35,11 @@ To run your queries using transactions you will use the
$this->db->trans_start() and $this->db->trans_complete() functions as
follows::
- $this->db->trans_start(); $this->db->query('AN SQL QUERY...'); $this->db->query('ANOTHER QUERY...'); $this->db->query('AND YET ANOTHER QUERY...'); $this->db->trans_complete();
+ $this->db->trans_start();
+ $this->db->query('AN SQL QUERY...');
+ $this->db->query('ANOTHER QUERY...');
+ $this->db->query('AND YET ANOTHER QUERY...');
+ $this->db->trans_complete();
You can run as many queries as you want between the start/complete
functions and they will all be committed or rolled back based on success
@@ -61,7 +65,15 @@ If you have error reporting enabled in your config/database.php file
you'll see a standard error message if the commit was unsuccessful. If
debugging is turned off, you can manage your own errors like this::
- $this->db->trans_start(); $this->db->query('AN SQL QUERY...'); $this->db->query('ANOTHER QUERY...'); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) {     // generate an error... or use the log_message() function to log your error }
+ $this->db->trans_start();
+ $this->db->query('AN SQL QUERY...');
+ $this->db->query('ANOTHER QUERY...');
+ $this->db->trans_complete();
+
+ if ($this->db->trans_status() === FALSE)
+ {
+ // generate an error... or use the log_message() function to log your error
+ }
Enabling Transactions
=====================
@@ -70,7 +82,11 @@ Transactions are enabled automatically the moment you use
$this->db->trans_start(). If you would like to disable transactions you
can do so using $this->db->trans_off()::
- $this->db->trans_off() $this->db->trans_start(); $this->db->query('AN SQL QUERY...'); $this->db->trans_complete();
+ $this->db->trans_off();
+
+ $this->db->trans_start();
+ $this->db->query('AN SQL QUERY...');
+ $this->db->trans_complete();
When transactions are disabled, your queries will be auto-commited, just
as they are when running queries without transactions.
@@ -83,14 +99,29 @@ will cause your queries to be rolled back -- even if the queries produce
a valid result. To use test mode simply set the first parameter in the
$this->db->trans_start() function to TRUE::
- $this->db->trans_start(TRUE); // Query will be rolled back $this->db->query('AN SQL QUERY...'); $this->db->trans_complete();
+ $this->db->trans_start(TRUE); // Query will be rolled back
+ $this->db->query('AN SQL QUERY...');
+ $this->db->trans_complete();
Running Transactions Manually
=============================
If you would like to run transactions manually you can do so as follows::
- $this->db->trans_begin(); $this->db->query('AN SQL QUERY...'); $this->db->query('ANOTHER QUERY...'); $this->db->query('AND YET ANOTHER QUERY...'); if ($this->db->trans_status() === FALSE) {     $this->db->trans_rollback(); } else {     $this->db->trans_commit(); }
+ $this->db->trans_begin();
+
+ $this->db->query('AN SQL QUERY...');
+ $this->db->query('ANOTHER QUERY...');
+ $this->db->query('AND YET ANOTHER QUERY...');
+
+ if ($this->db->trans_status() === FALSE)
+ {
+ $this->db->trans_rollback();
+ }
+ else
+ {
+ $this->db->trans_commit();
+ }
.. note:: Make sure to use $this->db->trans_begin() when running manual
transactions, **NOT** $this->db->trans_start().