PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Ree
Forum Regular
Posts: 592 Joined: Fri Jun 10, 2005 1:43 am
Location: LT
Post
by Ree » Mon Jul 03, 2006 4:51 am
Can you use prepared statements in transactions? For example, is this valid when using PDO:
Code: Select all
$pdo = new PDO(...);
$sql1 = "INSERT INTO Table1 ...";
$sql2 = "INSERT INTO Table2 ...";
$pdo->beginTransaction();
$statement1 = $pdo->prepare($sql1);
$statement2 = $pdo->prepare($sql2);
$statement1->execute(array(...));
$statement2->execute(array(...));
$pdo->commit();
In the manual they only have transaction examples without prepared statements.
bdlang
Forum Contributor
Posts: 395 Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US
Post
by bdlang » Mon Jul 03, 2006 8:45 am
Did you try it?
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Mon Jul 03, 2006 11:11 am
Ree wrote: Can you use prepared statements in transactions? For example, is this valid when using PDO:
Code: Select all
$pdo = new PDO(...);
$sql1 = "INSERT INTO Table1 ...";
$sql2 = "INSERT INTO Table2 ...";
$pdo->beginTransaction();
$statement1 = $pdo->prepare($sql1);
$statement2 = $pdo->prepare($sql2);
$statement1->execute(array(...));
$statement2->execute(array(...));
$pdo->commit();
In the manual they only have transaction examples without prepared statements.
It is quite easy to try it once you have the code.
These are the type of queries that will implicitly end a transaction, hence, not supporting it.
http://dev.mysql.com/doc/refman/5.0/en/ ... ommit.html