query return question

View: New views
2 Messages — Rating Filter:   Alert me  

query return question

by Manu0310 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I am using a custom query on 1 of my models (an update query), so I
use $this->Model->query('update query here');

Does anyone know how to get a return value back, something like true
or false, I am asking because I want to set up commit and rollback
transactions on some queries, since I am doing a few updates on
different tables.

When I do:

 if($this->Model->query('update query here'))
 {
      // persist the data
 }
else
{
    $this->model->rollback();
}

I never enter the first condition , and it always rolls back even
though my database fields are actually updating.

Any help is appreciated,
Thanks
Emmanuel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: query return question

by monmonja :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I believe its like this

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

explanation is at http://monmonja.com/blog/2008/07/transaction-on-cakephp-12/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!