xref: /PHP-8.3/ext/oci8/tests/bug71148.phpt (revision a53e5617)
1--TEST--
2Bug #71448 (Binding reference overwritten on php7)
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8$target_dbs = array('oracledb' => true, 'timesten' => true);  // test runs on these DBs
9require __DIR__.'/skipif.inc';
10?>
11--FILE--
12<?php
13
14require __DIR__.'/connect.inc';
15
16// Initialize
17
18$stmtarray = array(
19    "CREATE OR REPLACE FUNCTION bindfunc(var1 varchar2, var2 varchar2)
20       RETURN varchar2
21       AS var3 VARCHAR2(20);
22       BEGIN
23         var3 := CONCAT(var1, var2);
24         RETURN var3;
25       END;",
26    "CREATE OR REPLACE PROCEDURE bindproc(var1 IN string, var2 IN string, var3 IN OUT string) IS
27       BEGIN
28         var3 := CONCAT(var1, var3);
29         var3 := CONCAT(var3, var2);
30       END;"
31);
32
33oci8_test_sql_execute($c, $stmtarray);
34
35// Run test
36
37function bindvar($stmt, $name, $var)
38{
39  oci_bind_by_name($stmt, $name, $var);
40}
41
42// Test 1: Bind input parameter in a local function
43$sql = "select :var1, :var2 from dual";
44$cache1 = "INSTR1";
45$cache2 = "INSTR2";
46
47echo "Test 1: Bind input parameter in a local function\n";
48$stmt = oci_parse($c, $sql);
49
50bindvar($stmt, ':var1', $cache1);
51bindvar($stmt, ':var2', $cache2);
52
53oci_execute($stmt);
54
55var_dump(oci_fetch_assoc($stmt));
56
57oci_free_statement($stmt);
58
59// Test 2: Bind output parameter in a local function
60$sql = "begin :output1 := 'OUTSTR1'; :output2 := 'OUTSTR2'; end;";
61$cache1 = "xxxxxx";
62$cache2 = "xxxxxx";
63
64echo "\nTest 2: Bind output parameter in a local function\n";
65$stmt = oci_parse($c, $sql);
66
67bindvar($stmt, ':output1', $cache1);
68bindvar($stmt, ':output2', $cache2);
69
70oci_execute($stmt);
71
72var_dump($cache1);
73var_dump($cache2);
74
75oci_free_statement($stmt);
76
77// Test 3: Bind output parameter within the same scope of execute
78$sql = "begin :output1 := 'OUTSTR1'; :output2 := 'OUTSTR2'; end;";
79$cache1 = "xxxxxx";
80$cache2 = "xxxxxx";
81
82echo "\nTest 3: Bind output parameter within the same scope of execute\n";
83$stmt = oci_parse($c, $sql);
84
85oci_bind_by_name($stmt, ":output1", $cache1);
86oci_bind_by_name($stmt, ":output2", $cache2);
87
88oci_execute($stmt);
89
90var_dump($cache1);
91var_dump($cache2);
92
93oci_free_statement($stmt);
94
95// Test 4: Bind output parameter within the same scope of execute
96$sql= "begin :output := bindfunc(:var1, :var2); end;";
97$cache1 = "STR1";
98$cache2 = "STR2";
99
100echo "\nTest 4: Bind output parameter within the same scope of execute\n";
101$stmt = oci_parse($c, $sql);
102
103oci_bind_by_name($stmt, ":var1", $cache1, -1);
104oci_bind_by_name($stmt, ":var2", $cache2, -1);
105oci_bind_by_name($stmt, ":output", $cache3, 100);
106
107oci_execute($stmt);
108
109var_dump($cache3);
110
111// Test 5: Bind IN OUT parameter in a local function
112
113$sql = "call bindproc(:var1, :var2, :var3)";
114$cache1 = 'STR1';
115$cache2 = 'STR2';
116$cache3 = ' ';
117
118echo "\nTest 5: Bind IN OUT parameter in a local function\n";
119$stmt = oci_parse($c, $sql);
120
121bindvar($stmt, ':var1', $cache1);
122bindvar($stmt, ':var2', $cache2);
123bindvar($stmt, ':var3', $cache3);
124
125oci_execute($stmt);
126
127var_dump($cache1);
128var_dump($cache2);
129var_dump($cache3);
130
131oci_free_statement($stmt);
132
133// Test 6: Bind IN OUT parameter within the same scope of execute
134
135$sql = "call bindproc(:var1, :var2, :var3)";
136$cache1 = 'STR1';
137$cache2 = 'STR2';
138$cache3 = ' ';
139
140echo "\nTest 6: Bind IN OUT parameter within the same scope of execute\n";
141$stmt = oci_parse($c, $sql);
142
143oci_bind_by_name($stmt, ":var1", $cache1, -1);
144oci_bind_by_name($stmt, ":var2", $cache2, -1);
145oci_bind_by_name($stmt, ":var3", $cache3, 100);
146
147oci_execute($stmt);
148
149var_dump($cache1);
150var_dump($cache2);
151var_dump($cache3);
152
153// Cleanup
154
155$stmtarray = array(
156    "DROP FUNCTION bindfunc",
157    "DROP PROCEDURE bindproc"
158);
159
160oci8_test_sql_execute($c, $stmtarray);
161
162?>
163--EXPECT--
164Test 1: Bind input parameter in a local function
165array(2) {
166  [":VAR1"]=>
167  string(6) "INSTR1"
168  [":VAR2"]=>
169  string(6) "INSTR2"
170}
171
172Test 2: Bind output parameter in a local function
173string(6) "xxxxxx"
174string(6) "xxxxxx"
175
176Test 3: Bind output parameter within the same scope of execute
177string(7) "OUTSTR1"
178string(7) "OUTSTR2"
179
180Test 4: Bind output parameter within the same scope of execute
181string(8) "STR1STR2"
182
183Test 5: Bind IN OUT parameter in a local function
184string(4) "STR1"
185string(4) "STR2"
186string(1) " "
187
188Test 6: Bind IN OUT parameter within the same scope of execute
189string(4) "STR1"
190string(4) "STR2"
191string(9) "STR1 STR2"
192