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