xref: /PHP-7.4/ext/pdo_pgsql/tests/bug_49985.phpt (revision 26dfce7f)
1--TEST--
2Bug #49985 (pdo_pgsql prepare() re-use previous aborted transaction)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6require __DIR__ . '/config.inc';
7require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
13$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
14$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15
16$db->exec("CREATE TABLE test (a int PRIMARY KEY)");
17
18for ($i = 0; $i < 3; $i++) {
19    try {
20        $db->beginTransaction();
21        $stmt = $db->prepare("INSERT INTO test (a) VALUES (?)");
22        var_dump($stmt->execute(array(1)));
23        $db->commit();
24    } catch (Exception $e) {
25        echo trim(current(explode("\n", $e->getMessage())))."\n";
26        $db->rollback();
27    }
28}
29
30?>
31--EXPECTF--
32bool(true)
33SQLSTATE[23505]: %stest_pkey%s
34SQLSTATE[23505]: %stest_pkey%s
35