简体   繁体   中英

Problem with php+oracle(OCI)

Catchable fatal error: Object of class OCI-Collection could not be converted to string in E:\\php\\htdocs\\PHPRPC\\func.php on line 318

The code:

$sql='BEGIN NCCM_INTERFACE_HISDETAIL(:orgcode,:inhiscode,:inputer,:items); END;';
$conn=oci_connect('chis','chis123','ORCL','UTF8');
$stmt = oci_parse($conn, $sql);
$collection = oci_new_collection($conn,"NCCM_INTERFACE_TABLE");
foreach ($items as $item)
{
    $collection->append($item);
}
oci_bind_by_name($stmt, ":orgcode", $orgcode, -1);
oci_bind_by_name($stmt, ":inhiscode", $inhiscode, -1);
oci_bind_by_name($stmt, ":inputer", $inputer, -1);
oci_bind_by_name($stmt, ":items", $collection,-1); //here the error line
$s=oci_execute($stmt);

Can anyone help me to sort out this issue? Thanks in Advance.

The issue is you are binding a collection object while Oracle expects the bound type to be SQLT_CHR , eg a VARCHAR . Thus, Oracle will try to use the bound object in a string context, which is not possible because the collection apparently has no __toString method implemented. Hence you get the error that the object could not be converted to string.

I am not sure on this, but try to supply a different type in the binding call, for instance:

oci_bind_by_name($stmt, ":items", $collection,-1, OCI_B_NTY);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM