Page 1 of 1

PDO Question

Posted: Mon Jul 03, 2006 4:51 am
by Ree
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.

Posted: Mon Jul 03, 2006 8:45 am
by bdlang
Did you try it?

Re: PDO Question

Posted: Mon Jul 03, 2006 11:11 am
by jmut
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