1--TEST-- 2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: interleaved with DBMS_OUTPUT 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(dirname(__FILE__).'/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(dirname(__FILE__).'/connect.inc'); 21 22// Initialization 23 24$stmtarray = array( 25 "drop table imp_res_get_dbmsoutput_tab_1", 26 "create table imp_res_get_dbmsoutput_tab_1 (c1 number, c2 varchar2(10))", 27 "insert into imp_res_get_dbmsoutput_tab_1 values (1, 'abcde')", 28 "insert into imp_res_get_dbmsoutput_tab_1 values (2, 'fghij')", 29 "insert into imp_res_get_dbmsoutput_tab_1 values (3, 'klmno')", 30 31 "drop table imp_res_get_dbmsoutput_tab_2", 32 "create table imp_res_get_dbmsoutput_tab_2 (c3 varchar2(1))", 33 "insert into imp_res_get_dbmsoutput_tab_2 values ('t')", 34 "insert into imp_res_get_dbmsoutput_tab_2 values ('u')", 35 "insert into imp_res_get_dbmsoutput_tab_2 values ('v')", 36 37 "create or replace procedure imp_res_get_dbmsoutput_proc as 38 c1 sys_refcursor; 39 begin 40 dbms_output.put_line('Line 1'); 41 open c1 for select * from imp_res_get_dbmsoutput_tab_1 order by 1; 42 dbms_sql.return_result(c1); 43 dbms_output.put_line('Line 2'); 44 open c1 for select * from imp_res_get_dbmsoutput_tab_2 order by 1; 45 dbms_sql.return_result(c1); 46 dbms_output.put_line('Line 3'); 47 open c1 for select * from dual; 48 dbms_sql.return_result (c1); 49 end;" 50); 51 52oci8_test_sql_execute($c, $stmtarray); 53 54// Turn DBMS_OUTPUT on 55function setserveroutputon($c) 56{ 57 $s = oci_parse($c, "begin dbms_output.enable(null); end;"); 58 oci_execute($s); 59} 60 61function getdbmsoutput_do($c) 62{ 63 $s = oci_parse($c, "begin dbms_output.get_line(:ln, :st); end;"); 64 oci_bind_by_name($s, ":ln", $ln, 100); 65 oci_bind_by_name($s, ":st", $st, -1, SQLT_INT); 66 $res = false; 67 while (($succ = oci_execute($s)) && !$st) { 68 $res[] = $ln; // append each line to the array 69 } 70 return $res; 71} 72 73setserveroutputon($c); 74 75// Run Test 76 77echo "Test 1\n"; 78 79$s = oci_parse($c, "begin imp_res_get_dbmsoutput_proc(); end;"); 80oci_execute($s); 81 82var_dump(getdbmsoutput_do($c)); 83 84while (($s1 = oci_get_implicit_resultset($s))) { 85 while (($row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { 86 foreach ($row as $item) { 87 echo " ".$item; 88 } 89 echo "\n"; 90 } 91} 92 93echo "Test 2\n"; 94 95$s = oci_parse($c, "begin imp_res_get_dbmsoutput_proc(); end;"); 96oci_execute($s); 97 98while (($s1 = oci_get_implicit_resultset($s))) { 99 while (($row = oci_fetch_array($s1, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { 100 foreach ($row as $item) { 101 echo " ".$item; 102 } 103 echo "\n"; 104 } 105} 106 107var_dump(getdbmsoutput_do($c)); 108 109// Clean up 110 111$stmtarray = array( 112 "drop procedure imp_res_get_dbmsoutput_proc", 113 "drop table imp_res_get_dbmsoutput_tab_1", 114 "drop table imp_res_get_dbmsoutput_tab_2" 115); 116 117oci8_test_sql_execute($c, $stmtarray); 118 119?> 120===DONE=== 121<?php exit(0); ?> 122--EXPECT-- 123Test 1 124array(3) { 125 [0]=> 126 string(6) "Line 1" 127 [1]=> 128 string(6) "Line 2" 129 [2]=> 130 string(6) "Line 3" 131} 132 1 abcde 133 2 fghij 134 3 klmno 135 t 136 u 137 v 138 X 139Test 2 140 1 abcde 141 2 fghij 142 3 klmno 143 t 144 u 145 v 146 X 147array(3) { 148 [0]=> 149 string(6) "Line 1" 150 [1]=> 151 string(6) "Line 2" 152 [2]=> 153 string(6) "Line 3" 154} 155===DONE=== 156