【问题标题】:PDO OCI PHP pass array parameter to stored procedurePDO OCI PHP 将数组参数传递给存储过程
【发布时间】:2016-12-16 17:21:30
【问题描述】:

我在 oracle 中有一个这样定义的集合类型:

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

和存储过程:

PROCEDURE choice ( name IN VARCHAR2, order IN NUM_ARRAY )

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

谢谢

【问题讨论】:

    标签: php oracle stored-procedures pdo


    【解决方案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;
    }    
    

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 2010-11-07
      • 1970-01-01
      • 2016-04-05
      • 2021-12-29
      • 1970-01-01
      相关资源
      最近更新 更多