Why is PHP's OCI8/Oracle oci_bind_array_by_name not working for me?

巧了我就是萌 提交于 2019-12-02 21:38:56

问题


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;

回答1:


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);


来源:https://stackoverflow.com/questions/2960512/why-is-phps-oci8-oracle-oci-bind-array-by-name-not-working-for-me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!