At 12:59 +0200 1/13/03, Octavian Rasnita wrote:
Hi all,

I've seen the following code in MySQL cookbook:

 eval
 {
     # move some money from one person to the other
     $dbh->do ("UPDATE money SET amt = amt - 6 WHERE name = 'Eve'");
     $dbh->do ("UPDATE money SET amt = amt + 6 WHERE name = 'Ida'");
     # all statements succeeded; commit transaction
     $dbh->commit ( );
 };

 if ($@) # an error occurred
 {
     print "Transaction failed, rolling back. Error was:\n$@\n";
     # roll back within eval to prevent rollback
     # failure from terminating the script
     eval { $dbh->rollback ( ); };
 }

---

Well, I don't understand why I need to check if $@ is true or false.
If there wasn't any error, and the program should not rollback, in fact it
could give the rollback command because it won't produce any effect after
the commit command was given.

Am I wrong?

That's true, but don't you think it's a little confusing to write
code that issues a rollback back after a successful transaction?

It's also an additional statement that in that case is unnecessary
to issue, so what you suggest would be less efficient.


Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to