Search code examples
phporacleplsqlbooleanoracle-call-interface

PHP & Oracle - Binding a boolean to an oracle function call via php fails


I have an oracle function, that i am trying to access via php:

FUNCTION internInsertData( RefId  IN NUMBER, nProjektId  IN NUMBER, nKeepMaster IN NUMBER, Position IN NUMBER,CheckPosition IN BOOLEAN, TeilanlageId IN NUMBER,  TAElementId IN NUMBER)

This function needs a boolean parameter "CheckPosition", which seems to cause an error when binding a value using a variable to it.

When i run

$result="";
$sql ="BEGIN :result := PRO_1.PKG_REGELELEMENT.internInsertData(28236,653,1,1,true,123,42741); END;";

$stmt = oci_parse($this->oracle->getConnection(), $sql);

oci_bind_by_name($stmt, ":result", $result,12345);
oci_execute($stmt);

everything works fine.

I want to pass the values by binding.

But when i bind a boolean variable to the call, it fails to execute:

    $booli = true;
    $result="";

    $sql ="BEGIN :result := PRO_1.PKG_REGELELEMENT.internInsertData(28236,653,1,1,:booli,123,42741); END;";
    $stmt = oci_parse($this->oracle->getConnection(), $sql);
    oci_bind_by_name($stmt, ":result", $result,12345);
    oci_bind_by_name($stmt, ":booli", $booli,12345);
    oci_execute($stmt);

This causes a warning & the PL/SQL script stops:

PLS-00306: wrong number or types of arguments in call to 'INTERNINSERTDATA'

It seems that i am not binding the boolean the right way. Binding to the other numeric parameters works. Only the boolean doesn't. What am i missing ?


Solution

  • It seems that it is not possible to bind boolean data using less than Oracle 12c, like swstephe said in his comment.

    You will have to pass the value inline, like this:

    $sql ="BEGIN :result := PRO_1.PKG_REGELELEMENT.internInsertData(28236,653,1,1, true,123,42741); END;";

    Or use SQLT_BOL if you are able to use Oracle 12c or greater.