如何在PHP中绑定Oracle关联数组?

时间:2019-08-30 00:41:56

标签: php oracle binding associative-array oci

我在php中有一个具有复杂类型请求的方法。在我的方法中,我必须将请求绑定为接收关联数组的oracle过程/函数中的参数。

我尝试使用oci_bind_array_by_name。

class ExampleRequest   {
    /**
     * @soap
     * @var string
     */
    public  $Email;    
    /**
     * @soap
      * @minOccurs 0
     * @var ExampleItem[]
     */
    public  $ExampleItems;
}

class ExampleItem  {
    /**
     * @soap
     * @var string
     */
    public $Type;    
    /**
     * @soap     
     * @var integer
     */
    public $Points;    
}

//Test(ExampleRequest) 
public function Test($request)
    {
...
$sql = "BEGIN PROCEDURE_TEST(:p1, :p2, :p3);END;";
$res = oci_parse($this->dbCon, $sql);
oci_bind_by_name($res, ":p1", $request->Email);
oci_bind_array_by_name($res, ":p2", $request->ExampleItems->Type,count($request->ExampleItems->Type), -1, SQLT_CHR);
oci_bind_array_by_name($res, ":p3", $request->ExampleItems->Points,count($request->ExampleItems->Points), -1, SQLT_INT);
if (!oci_execute($res)){
   throw new SoapFault(4, "Internal server error");
}
...
}
$request = new ExampleRequest();
$request->ExampleItems= new ExampleItem();
$request->Email = "example@outlook.com";  
$request->ExampleItems->Type= array('A','B');
$request->ExampleItems->Points= array('587', '19'); 
$client->Test($request);
TYPE array1 IS TABLE OF VARCHAR2(50) INDEX BY PLS_INTEGER;
TYPE array2 IS TABLE OF NUMBER(10) INDEX BY PLS_INTEGER;

PROCEDURE_TEST(p_email IN VARCHAR2, p_type IN array1, p_points IN array2) IS 
BEGIN
  DELETE FROM TEMP;
  FOR i IN 1 .. p_type.COUNT
  LOOP
     INSERT INTO TEMP (x1, x2, x3)
     VALUES (p_type(i), p_points(i), i);
  END LOOP;
  COMMIT;

  FOR cnt IN (SELECT TBL.ID ID_TBL, TMP.X1, TMP.X2 FROM TABLEA TBL, TEMP TMP WHERE TBL.TYPE = TEMP.X1)
  LOOP
     UPDATE TABLEA SET CODE = CODE + cnt.X2 WHERE ID = cnt.ID_TBL;
     COMMIT;
   END LOOP;
  DELETE FROM TEMP;

END;

执行时发生错误,因为不幸地执行了与SoapFault的行,并且出现错误:object(SoapFault)#4 ...

0 个答案:

没有答案