php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80410 PDO->inTransaction return false after $stmt->execute() in 8.0
Submitted: 2020-11-24 16:33 UTC Modified: 2020-11-25 16:20 UTC
From: smissot at gmail dot com Assigned:
Status: Closed Package: PDO MySQL
PHP Version: 8.0.0RC5 OS: Debian
Private report: No CVE-ID: None
 [2020-11-24 16:33 UTC] smissot at gmail dot com
Description:
------------
PHP 8.0.0RC5 (cli) (built: Nov 19 2020 19:38:09) ( NTS )
MariaDB Version: 10.5.6-MariaDB-1:10.5.6+maria~focal

When executing a PDO statement, inTransaction() returns false afterwards.

This was not the case in PHP7.4 and before. Once I tested our application on PHP8.0RC5 I encountered this issue.

I am using ATTR_EMULATE_PREPARES as we have other issues when this is turned off.
In our application, we do have nested transactions due to Laravel
s testing framework, so this issue may be related to this.

Test script:
---------------
// SQL Query grabbed from mysql.general_log that is executed by both 7.4 and 8.0RC5
CALL myProcedure('2')

// Prepare
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
$stmt = $pdo->prepare('CALL myProcedure(?);', [\PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL]);
$stmt->bindValue(1, '2');


// 7.4
dump($pdo->inTransaction()); // true
$exec = $stmt->execute();
dump($pdo->inTransaction()); // true

// 8.0RC5
dump($pdo->inTransaction()); // true
$exec = $stmt->execute();
dump($pdo->inTransaction()); // false

Expected result:
----------------
true
true

Actual result:
--------------
true
false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-24 16:45 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2020-11-24 16:45 UTC] danack@php.net
> I am using ATTR_EMULATE_PREPARES as we have other issues 
> when this is turned off.
> In our application, we do have nested transactions due to
> Laravel's testing framework, so this issue may be related to this.

Well, my spidey sense is tingling.

That sounds a whole lot like you are dependent on some edge-case condition if using ATTR_EMULATE_PREPARES makes it 'work'.

If you want someone to look at this, please can you spend the effort to extract a reproduce case? I highly doubt anyone is going to be able to investigate this issue, even if they wanted to, without that as no-one would even know where to start looking.
 [2020-11-24 17:01 UTC] smissot at gmail dot com
-Status: Feedback +Status: Open
 [2020-11-24 17:01 UTC] smissot at gmail dot com
Of course! I will need some time to strip this down to a reproduceable piece, once I have it I will report back here.
 [2020-11-24 17:11 UTC] nikic@php.net
The behavior of inTransaction() changed in PHP 8. Now it is reporting the actual transaction state, rather than what PDO thinks the transaction state is.

If you are executing a query that implicitly commits the transaction (see https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html), then inTransaction() will now indeed return false after the query.
 [2020-11-25 16:20 UTC] smissot at gmail dot com
-Summary: PDO closes active transaction after $stmt->execute() +Summary: PDO->inTransaction return false after $stmt->execute() in 8.0 -Status: Open +Status: Closed
 [2020-11-25 16:20 UTC] smissot at gmail dot com
Hello Nikic,

Thanks for your reply, you are 100% correct, the statement contained some cases where an implicit commit was done. I will close the bug report now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC