xref: /PHP-8.3/ext/oci8/tests/error_parse.phpt (revision a53e5617)
1--TEST--
2Test error handling when persistent connection is passed to oci_error()
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11
12// As part of the fix for Bug 42134, an error handling difference was
13// noticed when oci_error() was passed a persistent connection.  This
14// was fixed and the behavior of oci_error() for all connections types
15// was made consistent.
16
17require __DIR__.'/details.inc';
18
19// Test parse error for normal connection
20
21if (!empty($dbase)) {
22    $c1 = oci_connect($user,$password,$dbase);
23}
24else {
25    $c1 = oci_connect($user,$password);
26}
27
28$s = @oci_parse($c1, "select ' from dual");
29if (!$s) {
30    echo "Normal connection: Parse error\n";
31    $m = oci_error($c1);
32    var_dump($m);
33}
34
35// Test parse error for new connection
36
37if (!empty($dbase)) {
38    $c2 = oci_new_connect($user,$password,$dbase);
39}
40else {
41    $c2 = oci_new_connect($user,$password);
42}
43
44$s = @oci_parse($c2, "select ' from dual");
45if (!$s) {
46    echo "New connection: Parse error\n";
47    $m = oci_error($c2);
48    var_dump($m);
49}
50
51// Test parse error for persistent connection
52
53if (!empty($dbase)) {
54    $c3 = oci_pconnect($user,$password,$dbase);
55}
56else {
57    $c3 = oci_pconnect($user,$password);
58}
59
60$s = @oci_parse($c3, "select ' from dual");
61if (!$s) {
62    echo "Persistent connection: Parse error\n";
63    $m = oci_error($c3);
64    var_dump($m);
65}
66
67// Verify that passing no connection doesn't affect future calls
68
69$m = oci_error();
70echo "No connection: error: ";
71var_dump($m);
72
73// Check the errors are still accessible in the respective handles
74
75$m = oci_error($c1);
76echo "Normal connection (take #2): Parse error: ";
77echo $m["message"], "\n";
78
79$m = oci_error($c2);
80echo "New connection (take #2): Parse error: ";
81echo $m["message"], "\n";
82
83$m = oci_error($c3);
84echo "Persistent connection (take #2): Parse error: ";
85echo $m["message"], "\n";
86
87// Now create a new error for a normal connection and check all again
88
89$s = @oci_new_collection($c1, "ABC");
90$m = oci_error($c1);
91echo "Normal connection: New Collection error: ";
92echo $m["message"], "\n";
93
94$m = oci_error($c2);
95echo "New connection (take #3): Parse error: ";
96echo $m["message"], "\n";
97
98$m = oci_error($c3);
99echo "Persistent connection (take #3): Parse error: ";
100echo $m["message"], "\n";
101
102echo "Done\n";
103
104?>
105--EXPECTF--
106Normal connection: Parse error
107array(4) {
108  ["code"]=>
109  int(1756)
110  ["message"]=>
111  string(48) "ORA-01756: %s"
112  ["offset"]=>
113  int(0)
114  ["sqltext"]=>
115  string(0) ""
116}
117New connection: Parse error
118array(4) {
119  ["code"]=>
120  int(1756)
121  ["message"]=>
122  string(48) "ORA-01756: %s"
123  ["offset"]=>
124  int(0)
125  ["sqltext"]=>
126  string(0) ""
127}
128Persistent connection: Parse error
129array(4) {
130  ["code"]=>
131  int(1756)
132  ["message"]=>
133  string(48) "ORA-01756: %s"
134  ["offset"]=>
135  int(0)
136  ["sqltext"]=>
137  string(0) ""
138}
139No connection: error: bool(false)
140Normal connection (take #2): Parse error: ORA-01756: %s
141New connection (take #2): Parse error: ORA-01756: %s
142Persistent connection (take #2): Parse error: ORA-01756: %s
143Normal connection: New Collection error: OCI-22303: type ""."ABC" not found
144New connection (take #3): Parse error: ORA-01756: %s
145Persistent connection (take #3): Parse error: ORA-01756: %s
146Done
147