[php-src] Issue #8735: Firebird PDO begintransaction fails after query
| From: | janderk2 | Date: | Wed, 08 Jun 2022 20:12:22 +0000 |
| Subject: | [php-src] Issue #8735: Firebird PDO begintransaction fails after query | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241691@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8735
Author: janderk2
### Description
The following code:
```php
<?php
// Step 1: Perform a query
$sql = "SELECT 1 FROM anytable ROWS 1";
$statement = $pdo->prepare($sql);
$statement->execute();
$result = $statement->fetch(PDO::FETCH_ASSOC);
// Step 2: Perform a query in transaction
$pdo->beginTransaction(); // Fatal error on this line: Uncaught PDOException: There is already
an active transaction
$statement = $pdo->prepare($sql);
$statement->execute();
$result = $statement->fetch(PDO::FETCH_ASSOC);
$pdo->commit();
````
Resulted in this output:
Fatal error: Uncaught PDOException: There is already an active transaction in ...
But I expected this output instead:
No exception. This works fine with mysql PDO. The
[manual](https://www.php.net/manual/en/pdo.begintransaction.php) says:
>Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via
>the PDO object instance are not committed until you end the transaction by calling
>[PDO::commit()](https://www.php.net/manual/en/pdo.commit.php). Calling
>[PDO::rollBack()](https://www.php.net/manual/en/pdo.rollback.php) will roll back all changes to the
>database and return the connection to autocommit.
It does not turn off autocommit. The workaround is to turn autocommit before calling the
transaction:
````php
$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
$pdo->beginTransaction();
// Do database stuff
$pdo->commit();
$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
````
### PHP Version
PHP 7.4 & 8.1.6
### Operating System
_No response_