PHP:将变量绑定到表类型输出参数 [英] PHP: Binding variable to table type output parameter

查看:61
本文介绍了PHP:将变量绑定到表类型输出参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在绑定输出参数时遇到了一个问题,即从 Oracle 数据库返回一个表.

Ok I'm having an issue binding output param which is to return a table from an Oracle db.

这是一个例子:

procedure_name(
    p_first IN NUMBER,
    p_second IN VARCHAR2,
    x_table_name OUT some_table_type,
    x_row_count OUT NUMBER
);

在使用此过程的 oracle 中一切正常.

Everything works fine in oracle working with this procedure.

我来到 PHP 我尝试了这个但没有去:

I come over to PHP I try this and no go:

$first = 55;
$second = 'Hello';

$stm = oci_parse($conn, "begin procedure_name(:p_first, :p_second, :x_table_name, :x_row_count)); end;"); 
oci_bind_by_name($stm, ":p_first", $first, 11, SQLT_INT);
oci_bind_by_name($stm, ":p_second", $second, 11, SQLT_INT);
oci_bind_by_name($stm, ":x_table_name", $table_output, -1, OCI_B_NTY);
oci_bind_by_name($stm, ":x_row_count", $table_row_count, 11, SQLT_INT);

oci_execute($stm);

结果我回来了:ORA-01008:并非所有变量都绑定.

And as a result I Get back: ORA-01008: not all variables bound.

现在我仍然需要弄清楚如何将变量 $table_output 作为一个对象数组或只是一个 assoc 数组来获取,但还没有那么远:/

Now I do still need to figure out how to fetch the variable $table_output as an array of objects or just an assoc array, but haven't gotten that far yet :/

推荐答案

该问题已通过使用解决:

The issue was resolved by using:

 $table_output = oci_new_collection($conn,'some_table_type','schema');

绑定前.

一个很好的资源是第 204 到 212 页:http://www.oracle.com/technetwork/database/database-technologies/php/201212-ug-php-oracle-1884760.pdf

A great resource has been page 204 to 212 of: http://www.oracle.com/technetwork/database/database-technologies/php/201212-ug-php-oracle-1884760.pdf

它有很多关于如何从 Oracle 过程和函数中获取自定义字段和表类型数据的示例.

It has plenty of examples of how to fetch custom field and table type data from Oracle procedures and functions.

这篇关于PHP:将变量绑定到表类型输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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