Monmonja Programming Blog

July 31, 2008

Transaction on cakephp 1.2

Filed under: Programming — Tags: , — admin @ 3:02 am

The execute function had been removed from cakephp 1.2 and this left us with use the query function. If you need to use transaction on cakephp 1.2 here is the most simple example.

Update Dec,20,09: If this doesn’t work then head over http://almondmendoza.com/2009/12/10/transaction-on-cakephp-when-using-oracle/

$this->Model->begin();
$returnQuery = $this->Model->query($query);
if($returnQuery !== false){
$this->Model->commit();
}else{
$this->Model->rollback();
}

$this->Model->begin();
begin will start the transaction

$returnQuery = $this->Model->query($query);
will execute your query (but not and assign the returned value to the returnQuery variable

if($returnQuery !== false){
strict check if return the query returns false

$this->Model->commit();
commit the transaction

$this->Model->rollback();
cancel the transaction

Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • del.icio.us
  • StumbleUpon
  • TwitThis
  • Fark
  • Facebook
  • Technorati
  • Sphinn
  • Furl
  • Google Bookmarks
  • Mixx

2 Comments »

  1. [...] Second you can manually start the transaction Transaction in CakePHP 1.2 [...]

    Pingback by Transactions in CakePHP « Myles Kadusale’s Blog — May 18, 2009 @ 7:39 pm

  2. Works like magic yet very simple.

    Comment by @wehf — April 22, 2010 @ 11:04 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Monmonja Programming Blog is Digg proof thanks to caching by WP Super Cache