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.

$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
  • Mixx