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