xref: /PHP-8.0/ext/oci8/tests/imp_res_6.phpt (revision a555cc0b)
1--TEST--
2Oracle Database 12c Implicit Result Sets: alternating oci_fetch_* calls
3--SKIPIF--
4<?php
5if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
7require(__DIR__.'/skipif.inc');
8preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
9if (!(isset($matches[0]) && $matches[1] >= 12)) {
10    die("skip expected output only valid when using Oracle Database 12c or greater");
11}
12preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
13if (!(isset($matches[0]) && $matches[0] >= 12)) {
14    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
15}
16?>
17--FILE--
18<?php
19
20require(__DIR__.'/connect.inc');
21
22// Initialization
23
24$stmtarray = array(
25    "drop table imp_res_6_tab",
26    "create table imp_res_6_tab (c1 number, c2 varchar2(10))",
27    "insert into imp_res_6_tab values (1, 'a')",
28    "insert into imp_res_6_tab values (2, 'b')",
29    "insert into imp_res_6_tab values (3, 'c')",
30    "insert into imp_res_6_tab values (4, 'd')",
31    "insert into imp_res_6_tab values (5, 'e')",
32    "insert into imp_res_6_tab values (6, 'f')",
33
34    "create or replace procedure imp_res_6_proc as
35      c1 sys_refcursor;
36    begin
37      open c1 for select * from imp_res_6_tab order by 1;
38      dbms_sql.return_result(c1);
39    end;"
40);
41
42oci8_test_sql_execute($c, $stmtarray);
43
44// Run Test
45
46echo "Test 1\n";
47$s = oci_parse($c, "begin imp_res_6_proc(); end;");
48oci_execute($s);
49
50$row = oci_fetch_assoc($s);
51var_dump($row);
52$row = oci_fetch_row($s);
53var_dump($row);
54$row = oci_fetch_object($s);
55var_dump($row);
56$row = oci_fetch_array($s);
57var_dump($row);
58$row = oci_fetch_array($s, OCI_NUM);
59var_dump($row);
60$row = oci_fetch_array($s, OCI_ASSOC);
61var_dump($row);
62
63
64// Clean up
65
66$stmtarray = array(
67    "drop procedure imp_res_6_proc",
68    "drop table imp_res_6_tab",
69);
70
71oci8_test_sql_execute($c, $stmtarray);
72
73?>
74--EXPECTF--
75Test 1
76array(2) {
77  ["C1"]=>
78  string(1) "1"
79  ["C2"]=>
80  string(1) "a"
81}
82array(2) {
83  [0]=>
84  string(1) "2"
85  [1]=>
86  string(1) "b"
87}
88object(stdClass)#%d (2) {
89  ["C1"]=>
90  string(1) "3"
91  ["C2"]=>
92  string(1) "c"
93}
94array(4) {
95  [0]=>
96  string(1) "4"
97  ["C1"]=>
98  string(1) "4"
99  [1]=>
100  string(1) "d"
101  ["C2"]=>
102  string(1) "d"
103}
104array(2) {
105  [0]=>
106  string(1) "5"
107  [1]=>
108  string(1) "e"
109}
110array(2) {
111  ["C1"]=>
112  string(1) "6"
113  ["C2"]=>
114  string(1) "f"
115}
116