Search code examples
phporacle11giis-7.5oracle-call-interface

oci_bind_by_name: PHP Fatal error: Only variables can be passed by reference


I'm trying to call a function from an Oracle package and I'm getting this error:

PHP Fatal error: Only variables can be passed by reference

This is my code:

    $connection = $this->getConnection();

    if (!$connection){
        return null;
    }

    $s = oci_parse($connection, "begin my_package.my_function(
            :param1
        ); end;");

    //getting the error in this following line:
    oci_bind_by_name($s, ":param1", "13")


    if($result = oci_execute($s)){
             ....
    }
    ...

I've been looking at other posts with this exactly same error but none of them seem to be related with this issue.

I'm using PHP version 5.5.6 over IIS 7.5 in a Windows 7 machine.

This is the definition of the function at my pacakage:

FUNCTION my_function(param1 IN VARCHAR2) RETURN CLOB IS
BEGIN
-- etc...
-- etc...
END;

Solution

  • Third parameter of oci_bind_by_name is passed by reference, hence you need to store it in a variable first:

    $param1 = "13";
    oci_bind_by_name($s, ":param1", $param1);