1--TEST--
2PDO_Firebird: auto commit
3--EXTENSIONS--
4pdo_firebird
5--SKIPIF--
6<?php require('skipif.inc'); ?>
7--XLEAK--
8A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9See https://github.com/FirebirdSQL/firebird/issues/7849
10--FILE--
11<?php
12/* Part of the error messages probably vary depending on the version of Firebird,
13 * so it won't check them in detail. */
14
15require("testdb.inc");
16$table = "autocommit_pdo_firebird";
17
18echo "========== in auto commit mode ==========\n";
19echo "auto commit mode ON\n";
20$dbh = getDbConnection();
21$dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
22
23echo "create table and insert\n";
24$dbh->exec("CREATE TABLE {$table} (val INT)");
25$dbh->exec("INSERT INTO {$table} VALUES (35)");
26
27echo "new connection\n";
28unset($dbh);
29$dbh = new PDO(PDO_FIREBIRD_TEST_DSN, PDO_FIREBIRD_TEST_USER, PDO_FIREBIRD_TEST_PASS);
30
31$r = $dbh->query("SELECT * FROM {$table}");
32var_dump($r->fetchAll());
33
34echo "========== not in auto commit mode ==========\n";
35echo "auto commit mode OFF\n";
36$dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
37
38echo "insert, expect error\n";
39try {
40    $dbh->exec("INSERT INTO {$table} VALUES (35)");
41} catch (PDOException $e) {
42    echo $e->getMessage()."\n\n";
43}
44
45echo "select, expect error\n";
46try {
47    $r = $dbh->query("SELECT * FROM {$table}");
48} catch (PDOException $e) {
49    echo $e->getMessage()."\n\n";
50}
51
52echo "done!";
53?>
54--CLEAN--
55<?php
56require 'testdb.inc';
57$dbh = getDbConnection();
58@$dbh->exec("DROP TABLE autocommit_pdo_firebird");
59?>
60--EXPECTF--
61========== in auto commit mode ==========
62auto commit mode ON
63create table and insert
64new connection
65array(1) {
66  [0]=>
67  array(2) {
68    ["VAL"]=>
69    int(35)
70    [0]=>
71    int(35)
72  }
73}
74========== not in auto commit mode ==========
75auto commit mode OFF
76insert, expect error
77SQLSTATE[08003]: Connection does not exist: %s
78
79select, expect error
80SQLSTATE[08003]: Connection does not exist: %s
81
82done!
83