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