Apigility RPC for IBM i DB2

    Apigility Setup

    This example assumes a setup similar to the one described in Installing and Using Apigility on IBM i. The example repository can be found on github.

    Create New RPC

    Create a new RPC through the Apigility Admin Interface like normal. This will generate a Factory and Controller for the RPC service. Once that is done, I like to quickly set the RPC HTTP Method to be POST.

    Define Adapter in Controller

    The controller needs our database adapter in order to call stored procedures. We’ll define that with a private variable and initialize it in the controller’s constructor like so:

    Use Factory to Inject Adapter

    The defined database adapter, in this case ibmdb, needs to be injected to the controller through the RPC’s factory. We can do that with the service manager:

    Call the Stored Procedure

    Now that we have access to the database adapter, we can use the same connection resource in order to call our stored procedure. This allows us to us IN, OUT, and INOUT DB2 parameters.

    There we are! We have a simple and repeatable way to call stored procedures with RPCs.

    I made this article because I found it difficult to find an example where the developer was using the same database resource to call a stored procedure, as I haven’t found a way to bind parameters through the ZF2 IBM DB2 Statement object in a way that gives the output to the bound parameter. My solution was to get the statement resource and use it with the built in PHP DB2 functions.

    Leave a Reply

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