1--TEST-- 2Basic PL/SQL "BOOLEAN" (SQLT_BOL) bind test 3--EXTENSIONS-- 4oci8 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8require __DIR__.'/connect.inc'; 9preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); 10if (!(isset($matches[0]) && $matches[1] >= 12)) { 11 die("skip expected output only valid when using Oracle Database 12c or greater"); 12} 13preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); 14if (!(isset($matches[0]) && $matches[0] >= 12)) { 15 die("skip works only with Oracle 12c or greater version of Oracle client libraries"); 16} 17?> 18--FILE-- 19<?php 20 21require __DIR__.'/connect.inc'; 22 23// Run Test 24 25echo "Test 1\n"; 26 27$sql = "begin 28 :output1 := true; 29 :output2 := false; 30 end;"; 31 32$s = oci_parse($c, $sql); 33oci_bind_by_name($s, ':output1', $output1, -1, OCI_B_BOL); 34oci_bind_by_name($s, ':output2', $output2, -1, OCI_B_BOL); 35oci_execute($s); 36var_dump($output1); 37var_dump($output2); 38 39echo "Test 2\n"; 40 41$b = "abc"; // bind var type will change 42$sql = "begin :b := true; end;"; 43$s = oci_parse($c, $sql); 44oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL); 45oci_execute($s); 46var_dump($b); 47 48 49echo "Test 3\n"; 50 51$sql = 52 "begin 53 if (:input < 10) then 54 :output := true; 55 else 56 :output := false; 57 end if; 58end;"; 59$s = oci_parse($c, $sql); 60oci_bind_by_name($s, ':output', $output, -1, OCI_B_BOL); 61for ($input = 5; $input < 15; ++$input) { 62 oci_bind_by_name($s, ':input', $input); 63 oci_execute($s); 64 var_dump($output); 65} 66 67echo "Test 4\n"; 68 69$sql = 70"begin 71 if (mod(:userid,2) = 0) then 72 :b := true; 73 else 74 :b := false; 75 end if; 76end;"; 77$s = oci_parse($c, $sql); 78oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL); 79for ($userid = 1; $userid <= 10; ++$userid) { 80 oci_bind_by_name($s, ':userid', $userid, -1, SQLT_INT); 81 oci_execute($s); 82 var_dump($b); 83} 84 85echo "Test 5\n"; 86 87$sql = 88"declare 89 l boolean; 90begin 91 l := :b1; 92 :b1 := :b2; 93 :b2 := l; 94end;"; 95$s = oci_parse($c, $sql); 96$b1 = true; 97$b2 = false; 98var_dump($b1, $b2); 99oci_bind_by_name($s, ':b1', $b1, -1, OCI_B_BOL); 100oci_bind_by_name($s, ':b2', $b2, -1, OCI_B_BOL); 101oci_execute($s); 102var_dump($b1, $b2); 103 104?> 105--EXPECT-- 106Test 1 107bool(true) 108bool(false) 109Test 2 110bool(true) 111Test 3 112bool(true) 113bool(true) 114bool(true) 115bool(true) 116bool(true) 117bool(false) 118bool(false) 119bool(false) 120bool(false) 121bool(false) 122Test 4 123bool(false) 124bool(true) 125bool(false) 126bool(true) 127bool(false) 128bool(true) 129bool(false) 130bool(true) 131bool(false) 132bool(true) 133Test 5 134bool(true) 135bool(false) 136bool(false) 137bool(true) 138