|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-05-24 13:38 UTC] hans at velum dot net
Description:
------------
I am rewriting the Propel ORM framework to use PDO (instead of Creole) as the runtime database abstraction layer. In doing so, I have come accross a need (which I'm sure is shared by others using PDO in frameworks) for the ability to determine whether a transaction has already been started for a particular PDO object.
The basic problem is that I have nested code using transactions. Of course eventually, support for nested transactions would be nice for the databases that support it, but in the meantime it would be great if I could programmatically determine whether a connection had been started and avoid the PDOException being thrown when I attempt to beginTransaction() in mid-transaction.
E.g. something like this would make life easier:
$usetx = !$con->isInTransaction();
try {
if ($usetx) $con->beginTransaction();
/* db operations here */
if ($usetx) $con->commit();
} catch (Exception $e) {
if ($usetx) $con->rollback();
throw $e;
}
Reproduce code:
---------------
function save($con)
$con->beginTransaction();
insert($con);
insertRelated($con);
$con->commit();
}
function insert($con) {
$con->beginTransaction(); // PDOException when called from save()
$con->exec("INSERT....");
$con->exec("INSERT....");
$con->exec("INSERT....");
$con->commit();
}
Expected result:
----------------
Ability to check for transaction in nested insert() function and hence avoid PDOException.
Actual result:
--------------
PDOException
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
Unrelated to the actual request, you should not call beginTransaction() inside the "try {..}" body.