PDO OCI PHP将数组参数传递给存储过程

时间:2016-08-10 10:57:30

标签: php oracle stored-procedures pdo

我在oracle中定义了类似的集合类型:

CREATE OR REPLACE TYPE "NUM_ARRAY" AS TABLE OF NUMBER(8,0)  

和存储过程:

PROCEDURE choice ( name IN VARCHAR2, order IN NUM_ARRAY )

如何使用pdo和php绑定param? :$stmt->bindParam(':order ',...);

Thx

1 个答案:

答案 0 :(得分:1)

我不知道你是否还在寻找这个问题的答案,但如果其他人遇到同样的问题,我会给你答案。我在以下链接找到了答案。

http://www.oracle.com/technetwork/articles/fuecks-sps-095636.html

这是我创建的用于将参数传递给Oracle过程的函数。我正在使用的程序没有返回任何结果,因此这个函数没有捕获任何内容。

public function bindVariablesToProcedure($var1, $var2, $var3)
{
    $rtn = []; // initalize array
    if($this->dbconnect)
    {
        /* schema is your database schema
           BindVariable is your stored procedure */
        $bindSql = 'BEGIN schema.BindVariable(:var1, :var2, :var3); END;';

        /* The numbers for the fourth parameter are the character lengths
           that are in my database.  I found that without these numbers
           the "oci_bind_by_name" function would error out. */
        $bindRes = oci_parse($this->dbconnect, $bindSql);
        oci_bind_by_name($bindRes, ':var1', $var1, 100);
        oci_bind_by_name($bindRes, ':var2', $var2, 5);
        oci_bind_by_name($bindRes, ':var3', $var3, 100);

        if(oci_execute($bindRes))
        {
            $rtn['status'] = "success";
        }
        else
        {
            $e = oci_error($bindRes);  // For oci_execute errors pass the statement handle
            $rtn['bindErrorSql'] = $e['sqltext'];
            $rtn['bindErrorCode'] = $e['code'];
            $rtn['bindErrorMsg'] = $e['message'];
            $rtn['status'] = "failed";
        }
    }
    return $rtn;
}