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