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