views:

117

answers:

1

I'm trying to bind a php variable to pl/sql array. The pl/sql procedure works fine when I execute it manually and set the bind, so I know that's not the problem. It's the oci_bind_array_by_name that is causing problems.

I get the following error message for the line in the PHP code below where I call the oci_bind_array_by_name function:

Warning: oci_bind_array_by_name() [function.oci-bind-array-by-name]: You must provide max length value for empty arrays

I'm confused because I am in fact providing a max length (250) in the function call per the documentation:

http://php.net/manual/en/function.oci-bind-array-by-name.php I'm using PHP 5.1.6

Here is the relevant PHP code:

$SQL = "BEGIN MYPKG.PROCESS_USERS(:USER_ID_ARRAY); END;";

$conn = self::getConnection();
$stmt = OCIParse($conn, $SQL);
$userIdArray= array(); /*I've also tried not initializing the OUT array (same error)
If I put some dummy value into the $userIdArray the procedure will run fine, but the results afterward will contain only that dummy value and not the output of the procedure*/
oci_bind_array_by_name($stmt,'USER_ID_ARRAY', $userIdArray, 250, -1, SQLT_VCS);

I have an array type defined in the package:

TYPE USER_ID_ARRAY IS TABLE OF VARCHAR2(250) INDEX BY BINARY_INTEGER;

The PROCESS_USERS function in an abbreviated form:
PROCEDURE PROCESS_USERS(p_userIdArray out USER_ID_ARRAY) AS
  --Code here which processes all waiting users and returns their IDs in p_userIdArray
END PROCESS USERS;
A: 

And I feel like a fool because I did not read the API closely enough. Apparently I was specifying the max_table_length but the error message was referring to the max_item_length which I left as -1... but that's a no-no since I'm binding an OUT parameter instead of an IN one.

Changed the bind like so and it now works:

oci_bind_array_by_name($stmt,'USER_ID_ARRAY', $userIdArray, 250, 250, SQLT_VCS);
RenderIn