xref: /PHP-8.3/ext/oci8/tests/commit_001.phpt (revision a53e5617)
1--TEST--
2Test OCI_NO_AUTO_COMMIT constant
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
9require __DIR__.'/skipif.inc';
10?>
11--FILE--
12<?php
13
14require __DIR__.'/connect.inc';
15require __DIR__.'/create_table.inc';
16
17$insert_sql = "insert into ".$schema.$table_name." (id, value) values (1,1)";
18
19if (!($s = oci_parse($c, $insert_sql))) {
20    die("oci_parse(insert) failed!\n");
21}
22
23/* check with OCI_NO_AUTO_COMMIT mode  */
24for ($i = 0; $i<3; $i++) {
25    if (!oci_execute($s, OCI_NO_AUTO_COMMIT)) {
26        die("oci_execute(insert) failed!\n");
27    }
28}
29
30for ($i = 0; $i<3; $i++) {
31    if (!oci_execute($s, OCI_DEFAULT)) {
32        die("oci_execute(insert) failed!\n");
33    }
34}
35
36
37var_dump(oci_rollback($c));
38
39$select_sql = "select * from ".$schema.$table_name."";
40
41if (!($select = oci_parse($c, $select_sql))) {
42    die("oci_parse(select) failed!\n");
43}
44
45/* oci_fetch_all */
46if (!oci_execute($select)) {
47    die("oci_execute(select) failed!\n");
48}
49var_dump(oci_fetch_all($select, $all));
50var_dump($all);
51
52/* ocifetchstatement */
53if (!oci_execute($s)) {
54    die("oci_execute(select) failed!\n");
55}
56
57$insert_sql = "insert into ".$schema.$table_name." (id, value) values (1,1)";
58
59if (!($s = oci_parse($c, $insert_sql))) {
60    die("oci_parse(insert) failed!\n");
61}
62
63for ($i = 0; $i<3; $i++) {
64    if (!oci_execute($s, OCI_DEFAULT)) {
65        die("oci_execute(insert) failed!\n");
66    }
67}
68
69var_dump(oci_commit($c));
70
71/* oci_fetch_all */
72if (!oci_execute($select)) {
73    die("oci_execute(select) failed!\n");
74}
75var_dump(oci_fetch_all($select, $all));
76var_dump($all);
77
78
79require __DIR__.'/drop_table.inc';
80
81echo "Done\n";
82?>
83--EXPECT--
84bool(true)
85int(0)
86array(5) {
87  ["ID"]=>
88  array(0) {
89  }
90  ["VALUE"]=>
91  array(0) {
92  }
93  ["BLOB"]=>
94  array(0) {
95  }
96  ["CLOB"]=>
97  array(0) {
98  }
99  ["STRING"]=>
100  array(0) {
101  }
102}
103bool(true)
104int(4)
105array(5) {
106  ["ID"]=>
107  array(4) {
108    [0]=>
109    string(1) "1"
110    [1]=>
111    string(1) "1"
112    [2]=>
113    string(1) "1"
114    [3]=>
115    string(1) "1"
116  }
117  ["VALUE"]=>
118  array(4) {
119    [0]=>
120    string(1) "1"
121    [1]=>
122    string(1) "1"
123    [2]=>
124    string(1) "1"
125    [3]=>
126    string(1) "1"
127  }
128  ["BLOB"]=>
129  array(4) {
130    [0]=>
131    NULL
132    [1]=>
133    NULL
134    [2]=>
135    NULL
136    [3]=>
137    NULL
138  }
139  ["CLOB"]=>
140  array(4) {
141    [0]=>
142    NULL
143    [1]=>
144    NULL
145    [2]=>
146    NULL
147    [3]=>
148    NULL
149  }
150  ["STRING"]=>
151  array(4) {
152    [0]=>
153    NULL
154    [1]=>
155    NULL
156    [2]=>
157    NULL
158    [3]=>
159    NULL
160  }
161}
162Done
163