>
> $db->insert('venue', $venueData);
> $venueid = $db->lastInsertId();
>
> $db->insert('contactperson', $contactData);
> $db->insert('opendays', $opendays);
> $db->commit();
>
> try{
> $this->uploadFiles($venueid);
> }catch(Exception $e){
> $db->rollBack();
> }
>
In the sequence of your code above, you can never roll back the database
inserts, because you're calling commit() before you get to calling
uploadFiles(). When you call rollback(), there are no database changes
pending. Also, I didn't see where you began the transaction. You can't
rollback anything if you're running in auto-commit mode, which you are
unless you call beginTransaction().
Instead, try something like this:
$db->beginTransaction();
$db->insert('venue', $venueData);
$venueid = $db->lastInsertId();
$db->insert('contactperson', $contactData);
$db->insert('opendays', $opendays);
try{
$this->uploadFiles($venueid);
// if uploadFiles() throws an exception, the following line will be
skipped:
$db->commit();
}catch(Exception $e){
$db->rollBack();
}
Regards,
Bill Karwin
--
View this message in context: http://www.nabble.com/Transactions---Forcing-a-Rollback-Action-tp19142158p19151464.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论