php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: remy dot fox at hotmail dot com
New email:
PHP Version: OS:

 

 [2018-11-07 11:51 UTC] remy dot fox at hotmail dot com
Description:
------------
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: https://github.com/php/php-src/blob/master/ext/pdo/pdo_dbh.c (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.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-08 16:22 UTC] adambaratz@php.net
-Type: Bug +Type: Feature/Change Request
 [2018-11-08 16:22 UTC] adambaratz@php.net
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] adambaratz@php.net
-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] adambaratz@php.net
-Operating System: Windows +Operating System: -PHP Version: 7.2.11 +PHP Version: irrelevant
 [2018-11-08 17:21 UTC] requinix@php.net
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] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-09-23 09:53 UTC] nikic@php.net
Has been implemented by https://github.com/php/php-src/pull/4996.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jan 14 12:01:30 2025 UTC