Mysql transactions issue

Posted by Stann on Stack Overflow See other posts from Stack Overflow or by Stann
Published on 2012-06-05T04:37:06Z Indexed on 2012/06/05 4:40 UTC
Read the original article Hit count: 218

Filed under:
|
|

In straight mysql script I'd do transactions like this:

START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;

i'm a little confused about how transactions work in PDO. It looks like there are beginTransaction() and commit() methods - so I'm not sure are these just convenience wrappers around staright SQL? or are they doing some more job behind the doors?

In other words - are these examples below essentially the same?

example 1:

$dbh->exec( 'START TRANSACTION' );
//...do some db work here...
$dbh->exec( "COMMIT" );

example 2:

$dbh->beginTransaction();
//...do some db work here...
$dbh->commit();

© Stack Overflow or respective owner

Related posts about mysql

Related posts about transactions