Bug->Req #77116 [Opn]: PDO inTransaction does not have the same value as SESSION_VARIABLE
Edit report at https://bugs.php.net/bug.php?id=77116&edit=1
ID: 77116
Updated by: adambaratz@php.net
Reported by: remy dot fox at hotmail dot com
Summary: PDO inTransaction does not have the same value as
SESSION_VARIABLE
Status: Open
-Type: Bug
+Type: Feature/Change Request
Package: PDO MySQL
Operating System: Windows
PHP Version: 7.2.11
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2018-11-07 11:51:57] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77116&edit=1
Thread (6 messages)