|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2014-10-31 16:44 UTC] mbeccati@php.net
 
-Summary:          Postgres/PDO inTransaction()
                   returns false while transaction is still active.
+Summary:          PDO_PGSQL::beginTransaction()
                   wrongly throws exception when not in transaction
-Status:           Open
+Status:           Analyzed
-Operating System: Linux/Ubuntu 14.04
+Operating System: *
-Assigned To:
+Assigned To:      mbeccati
  [2014-10-31 16:44 UTC] mbeccati@php.net
  [2014-10-31 18:00 UTC] mbeccati@php.net
  [2014-10-31 18:00 UTC] mbeccati@php.net
 
-Status: Analyzed
+Status: Closed
  [2014-11-18 20:34 UTC] ab@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 22:00:01 2025 UTC | 
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 ...