为什么PHP的OCI8/Oracle oci_bind_array_by_name对我不起作用? [英] Why is PHP's OCI8/Oracle oci_bind_array_by_name not working for me?

查看:180
本文介绍了为什么PHP的OCI8/Oracle oci_bind_array_by_name对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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 我正在使用PHP 5.1.6

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

以下是相关的PHP代码:

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;

推荐答案

我觉得自己很傻,因为我没有足够仔细地阅读API.显然我指定的是max_table_length,但错误消息指向的是我留为-1的max_item_length ...但这是不行,因为我绑定的是OUT参数而不是IN参数.

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

这篇关于为什么PHP的OCI8/Oracle oci_bind_array_by_name对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆