为什么 PHP 的 OCI8/Oracle oci_bind_array_by_name 对我不起作用?

发布于 2024-09-03 13:13:00 字数 1402 浏览 3 评论 0原文

我正在尝试将 php 变量绑定到 pl/sql 数组。当我手动执行并设置绑定时,pl/sql 过程工作正常,所以我知道这不是问题。导致问题的是 oci_bind_array_by_name

对于下面的 PHP 代码中调用 oci_bind_array_by_name 函数的行,我收到以下错误消息:

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

我很困惑,因为实际上我在函数调用中提供了最大长度 (250)文档:

http://php.net/manual/ en/function.oci-bind-array-by-name.php 我正在使用 PHP 5.1.6

以下是相关的 PHP 代码:

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

我在包中定义了一个数组类型:

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-09-10 13:13:00

我感觉自己像个傻瓜,因为我没有仔细阅读 API。显然我指定了 max_table_length,但错误消息指的是 max_item_length,我将其保留为 -1...但这是一个禁忌,因为我绑定的是 OUT 参数而不是 IN 参数。

像这样更改绑定,它现在可以工作:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文