xref: /PHP-8.1/ext/oci8/tests/fetch_array.phpt (revision b5a14e6c)
1--TEST--
2oci_fetch_array()
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
22for ($i = 0; $i<3; $i++) {
23    if (!oci_execute($s)) {
24        die("oci_execute(insert) failed!\n");
25    }
26}
27
28if (!oci_commit($c)) {
29    die("oci_commit() failed!\n");
30}
31
32echo "Test 1\n";
33
34$select_sql = "SELECT * FROM ".$schema."".$table_name."";
35
36if (!($s = oci_parse($c, $select_sql))) {
37    die("oci_parse(select) failed!\n");
38}
39
40if (!oci_execute($s)) {
41    die("oci_execute(select) failed!\n");
42}
43while ($row = oci_fetch_array($s)) {
44    var_dump($row);
45}
46
47echo "Test 2\n";
48
49if (!oci_execute($s)) {
50    die("oci_execute(select) failed!\n");
51}
52while ($row = oci_fetch_array($s, OCI_NUM)) {
53    var_dump($row);
54}
55
56echo "Test 3\n";
57
58if (!oci_execute($s)) {
59    die("oci_execute(select) failed!\n");
60}
61while ($row = oci_fetch_array($s, OCI_ASSOC)) {
62    var_dump($row);
63}
64
65echo "Test 4\n";
66
67if (!oci_execute($s)) {
68    die("oci_execute(select) failed!\n");
69}
70while ($row = oci_fetch_array($s, OCI_BOTH)) {
71    var_dump($row);
72}
73
74echo "Test 5\n";
75
76if (!oci_execute($s)) {
77    die("oci_execute(select) failed!\n");
78}
79while ($row = oci_fetch_array($s, OCI_RETURN_LOBS)) {
80    var_dump($row);
81}
82
83echo "Test 6\n";
84
85if (!oci_execute($s)) {
86    die("oci_execute(select) failed!\n");
87}
88while ($row = oci_fetch_array($s, OCI_RETURN_NULLS)) {
89    var_dump($row);
90}
91
92echo "Test 7\n";
93
94if (!oci_execute($s)) {
95    die("oci_execute(select) failed!\n");
96}
97while ($row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS)) {
98    var_dump($row);
99}
100
101require __DIR__.'/drop_table.inc';
102
103echo "Done\n";
104?>
105--EXPECT--
106Test 1
107array(10) {
108  [0]=>
109  string(1) "1"
110  ["ID"]=>
111  string(1) "1"
112  [1]=>
113  string(1) "1"
114  ["VALUE"]=>
115  string(1) "1"
116  [2]=>
117  NULL
118  ["BLOB"]=>
119  NULL
120  [3]=>
121  NULL
122  ["CLOB"]=>
123  NULL
124  [4]=>
125  NULL
126  ["STRING"]=>
127  NULL
128}
129array(10) {
130  [0]=>
131  string(1) "1"
132  ["ID"]=>
133  string(1) "1"
134  [1]=>
135  string(1) "1"
136  ["VALUE"]=>
137  string(1) "1"
138  [2]=>
139  NULL
140  ["BLOB"]=>
141  NULL
142  [3]=>
143  NULL
144  ["CLOB"]=>
145  NULL
146  [4]=>
147  NULL
148  ["STRING"]=>
149  NULL
150}
151array(10) {
152  [0]=>
153  string(1) "1"
154  ["ID"]=>
155  string(1) "1"
156  [1]=>
157  string(1) "1"
158  ["VALUE"]=>
159  string(1) "1"
160  [2]=>
161  NULL
162  ["BLOB"]=>
163  NULL
164  [3]=>
165  NULL
166  ["CLOB"]=>
167  NULL
168  [4]=>
169  NULL
170  ["STRING"]=>
171  NULL
172}
173Test 2
174array(2) {
175  [0]=>
176  string(1) "1"
177  [1]=>
178  string(1) "1"
179}
180array(2) {
181  [0]=>
182  string(1) "1"
183  [1]=>
184  string(1) "1"
185}
186array(2) {
187  [0]=>
188  string(1) "1"
189  [1]=>
190  string(1) "1"
191}
192Test 3
193array(2) {
194  ["ID"]=>
195  string(1) "1"
196  ["VALUE"]=>
197  string(1) "1"
198}
199array(2) {
200  ["ID"]=>
201  string(1) "1"
202  ["VALUE"]=>
203  string(1) "1"
204}
205array(2) {
206  ["ID"]=>
207  string(1) "1"
208  ["VALUE"]=>
209  string(1) "1"
210}
211Test 4
212array(4) {
213  [0]=>
214  string(1) "1"
215  ["ID"]=>
216  string(1) "1"
217  [1]=>
218  string(1) "1"
219  ["VALUE"]=>
220  string(1) "1"
221}
222array(4) {
223  [0]=>
224  string(1) "1"
225  ["ID"]=>
226  string(1) "1"
227  [1]=>
228  string(1) "1"
229  ["VALUE"]=>
230  string(1) "1"
231}
232array(4) {
233  [0]=>
234  string(1) "1"
235  ["ID"]=>
236  string(1) "1"
237  [1]=>
238  string(1) "1"
239  ["VALUE"]=>
240  string(1) "1"
241}
242Test 5
243array(4) {
244  [0]=>
245  string(1) "1"
246  ["ID"]=>
247  string(1) "1"
248  [1]=>
249  string(1) "1"
250  ["VALUE"]=>
251  string(1) "1"
252}
253array(4) {
254  [0]=>
255  string(1) "1"
256  ["ID"]=>
257  string(1) "1"
258  [1]=>
259  string(1) "1"
260  ["VALUE"]=>
261  string(1) "1"
262}
263array(4) {
264  [0]=>
265  string(1) "1"
266  ["ID"]=>
267  string(1) "1"
268  [1]=>
269  string(1) "1"
270  ["VALUE"]=>
271  string(1) "1"
272}
273Test 6
274array(10) {
275  [0]=>
276  string(1) "1"
277  ["ID"]=>
278  string(1) "1"
279  [1]=>
280  string(1) "1"
281  ["VALUE"]=>
282  string(1) "1"
283  [2]=>
284  NULL
285  ["BLOB"]=>
286  NULL
287  [3]=>
288  NULL
289  ["CLOB"]=>
290  NULL
291  [4]=>
292  NULL
293  ["STRING"]=>
294  NULL
295}
296array(10) {
297  [0]=>
298  string(1) "1"
299  ["ID"]=>
300  string(1) "1"
301  [1]=>
302  string(1) "1"
303  ["VALUE"]=>
304  string(1) "1"
305  [2]=>
306  NULL
307  ["BLOB"]=>
308  NULL
309  [3]=>
310  NULL
311  ["CLOB"]=>
312  NULL
313  [4]=>
314  NULL
315  ["STRING"]=>
316  NULL
317}
318array(10) {
319  [0]=>
320  string(1) "1"
321  ["ID"]=>
322  string(1) "1"
323  [1]=>
324  string(1) "1"
325  ["VALUE"]=>
326  string(1) "1"
327  [2]=>
328  NULL
329  ["BLOB"]=>
330  NULL
331  [3]=>
332  NULL
333  ["CLOB"]=>
334  NULL
335  [4]=>
336  NULL
337  ["STRING"]=>
338  NULL
339}
340Test 7
341array(5) {
342  [0]=>
343  string(1) "1"
344  [1]=>
345  string(1) "1"
346  [2]=>
347  NULL
348  [3]=>
349  NULL
350  [4]=>
351  NULL
352}
353array(5) {
354  [0]=>
355  string(1) "1"
356  [1]=>
357  string(1) "1"
358  [2]=>
359  NULL
360  [3]=>
361  NULL
362  [4]=>
363  NULL
364}
365array(5) {
366  [0]=>
367  string(1) "1"
368  [1]=>
369  string(1) "1"
370  [2]=>
371  NULL
372  [3]=>
373  NULL
374  [4]=>
375  NULL
376}
377Done
378