1--TEST-- 2Basic PL/SQL "BOOLEAN" (SQLT_BOL) bind test 3--EXTENSIONS-- 4oci8 5--SKIPIF-- 6<?php 7require(__DIR__.'/connect.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// Run Test 23 24echo "Test 1\n"; 25 26$sql = "begin 27 :output1 := true; 28 :output2 := false; 29 end;"; 30 31$s = oci_parse($c, $sql); 32oci_bind_by_name($s, ':output1', $output1, -1, OCI_B_BOL); 33oci_bind_by_name($s, ':output2', $output2, -1, OCI_B_BOL); 34oci_execute($s); 35var_dump($output1); 36var_dump($output2); 37 38echo "Test 2\n"; 39 40$b = "abc"; // bind var type will change 41$sql = "begin :b := true; end;"; 42$s = oci_parse($c, $sql); 43oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL); 44oci_execute($s); 45var_dump($b); 46 47 48echo "Test 3\n"; 49 50$sql = 51 "begin 52 if (:input < 10) then 53 :output := true; 54 else 55 :output := false; 56 end if; 57end;"; 58$s = oci_parse($c, $sql); 59oci_bind_by_name($s, ':output', $output, -1, OCI_B_BOL); 60for ($input = 5; $input < 15; ++$input) { 61 oci_bind_by_name($s, ':input', $input); 62 oci_execute($s); 63 var_dump($output); 64} 65 66echo "Test 4\n"; 67 68$sql = 69"begin 70 if (mod(:userid,2) = 0) then 71 :b := true; 72 else 73 :b := false; 74 end if; 75end;"; 76$s = oci_parse($c, $sql); 77oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL); 78for ($userid = 1; $userid <= 10; ++$userid) { 79 oci_bind_by_name($s, ':userid', $userid, -1, SQLT_INT); 80 oci_execute($s); 81 var_dump($b); 82} 83 84echo "Test 5\n"; 85 86$sql = 87"declare 88 l boolean; 89begin 90 l := :b1; 91 :b1 := :b2; 92 :b2 := l; 93end;"; 94$s = oci_parse($c, $sql); 95$b1 = true; 96$b2 = false; 97var_dump($b1, $b2); 98oci_bind_by_name($s, ':b1', $b1, -1, OCI_B_BOL); 99oci_bind_by_name($s, ':b2', $b2, -1, OCI_B_BOL); 100oci_execute($s); 101var_dump($b1, $b2); 102 103?> 104--EXPECT-- 105Test 1 106bool(true) 107bool(false) 108Test 2 109bool(true) 110Test 3 111bool(true) 112bool(true) 113bool(true) 114bool(true) 115bool(true) 116bool(false) 117bool(false) 118bool(false) 119bool(false) 120bool(false) 121Test 4 122bool(false) 123bool(true) 124bool(false) 125bool(true) 126bool(false) 127bool(true) 128bool(false) 129bool(true) 130bool(false) 131bool(true) 132Test 5 133bool(true) 134bool(false) 135bool(false) 136bool(true) 137