|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77116 implement in_transaction handler for pdo_mysql
Submitted: 2018-11-07 11:51 UTC Modified: 2020-09-23 09:53 UTC
From: remy dot fox at hotmail dot com Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 + 12 = ?
Subscribe to this entry?

 [2018-11-07 11:51 UTC] remy dot fox at hotmail dot com
PDO has a function called 'inTransaction', which verifies whether a transaction is currently active. As far as I can see it calls a method 'in_transaction' here: (line 656). 

When I start the transaction using SQL ("START TRANSACTION") instead of the PDO API, the result of inTransaction is always false. However, I'm confident a transaction is running, because calling "ROLLBACK" does not commit any changes. On MariaDB, the following query results "1", too: SELECT SESSION_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME = 'in_transaction'.

So I suspect that there is something wrong with the inTransaction method. It only seems to work when it is called in combination with beginTransaction, rather than in any case that a transaction was started.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-08 16:22 UTC]
-Type: Bug +Type: Feature/Change Request
 [2018-11-08 16:22 UTC]
What you're experiencing is maybe not the best behavior, but pdo_mysql performing as it's written. This driver doesn't define an in_transaction method, so it defaults to checking the status of the bit flipped by the beginTransaction/rollBack/commit methods.

An in_transaction method could be implemented in ext/pdo_mysql/mysql_driver.c (see the definition of mysql_methods at the bottom of that file for where the connection is made). If there's a C API for checking transaction status, that would likely be more reliable than running a query. See the pgsql_handle_in_transaction function in ext/pdo_pgsql/pgsql_driver.c for an example of this. FWIW, pdo_pgsql is the only PDO driver shipped with PHP that implements this function.
 [2018-11-08 16:23 UTC]
-Summary: PDO inTransaction does not have the same value as SESSION_VARIABLE +Summary: implement in_transaction handler for pdo_mysql
 [2018-11-08 16:23 UTC]
-Operating System: Windows +Operating System: -PHP Version: 7.2.11 +PHP Version: irrelevant
 [2018-11-08 17:21 UTC]
The Python API gets its in_transaction from MYSQL->server_status & 1.
 [2018-11-12 12:42 UTC] remyfox at hotmail dot com
In MySQL table schema structure changes such as CREATE TABLE cause an automatic commit of the transaction. PDO.inTransaction always reacted to this, so I suspect that it does not only check a bit flipped by beginTransaction/rollBack/commit methods.
 [2018-11-12 13:09 UTC] remyfox at hotmail dot com
I see that my memory was not correct. Apparently, the implicit commit after a table schema modification is not noticed by the current PDO.inTransaction implementation.

Regardless, I would say this is a bug rather than a feature request.
 [2020-09-23 09:53 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-09-23 09:53 UTC]
Has been implemented by
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 16:03:12 2021 UTC