How to execute a Stored Procedure Oracle with ZF2

I was some problems to execute an oracle stored procedure in ZF2 with out params.

The following is an example, how finally I implemented the solution.

Procedure


CREATE OR REPLACE procedure sp_tmp(rtn out char) AS
begin

rtn := '1';

end sp_tmp;
/

 Call from ZF2 Model


        $adapter = $this->tableGateway->adapter;
        $statement = $adapter->createStatement();
        $statement->prepare("begin sp_tmp(:output); end;");

        $parameterContainer = new \Zend\Db\Adapter\ParameterContainer;
        //Uncomment this if you want to add IN params
        //$parameterContainer->offsetSet('inParam', '', $parameterContainer::TYPE_STRING); 
        $parameterContainer->offsetSetReference('output', 'output'); // Out parameter
        $statement->setParameterContainer($parameterContainer);
        $statement->execute();

        var_dump($parameterContainer->getNamedArray());

 Finally I got this:

array (size=1)
  'output' => &string '1' (length=1)

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEN