From: piotr dot m at shwrm dot com
Operating system: Linux/Ubuntu 14.04
PHP version: 5.5.13
Package: PDO PgSQL
Bug Type: Bug
Bug description:Postgres/PDO inTransaction() returns false while transaction is still active.
Description:
------------
PDOConnection->inTransaction() combined with PostgreSQL seems to return
false after a failed commit exception is caught by the try/catch block.
This problem seems to occur both in CLI mode and when called via FPM.
One more bit of information: the DB constraint that causes the duplicate
key exception is in "DEFERRABLE INITIALLY DEFERRED" mode so it will be
checked after COMMIT is called, not immediately after an update
statement is executed.
PHP: 5.5.13-1~dotdeb.1 (both FPM and CLI)
Postgresql: "PostgreSQL 9.3.4 on x86_64-unknown-linux-gnu, compiled by
gcc (Debian 4.7.2-5) 4.7.2, 64-bit"
Test script:
---------------
$con = new
\PDO('pgsql:host=127.0.0.1;port=5432;dbname=;user=;password=');
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->beginTransaction();
$prod = $con->prepare(/** QUERY THAT CAUSES SQLSTATE[23505]: Unique
violation: 7 ERROR: duplicate key value**/);
$prod->execute();
try {
var_dump($con->inTransaction());
$con->commit();
} catch (\Exception $e) {
var_dump($con->inTransaction());
$con->inTransaction() or $con->beginTransaction();
}
Expected result:
----------------
bool(true)
bool(true)
Actual result:
--------------
bool(true)
bool(false)
PHP Fatal error: Uncaught exception 'PDOException' with message 'There
is already an active transaction' in ...
--
Edit bug report at https://bugs.php.net/bug.php?id=67462&edit=1
--