PFeng
PFeng

Reputation: 101

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.

Upvotes: 0

Views: 3013

Answers (1)

Gordon
Gordon

Reputation: 317177

The issue is you are binding a collection object while Oracle expects the bound type to be SQLT_CHR, e.g. 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);

Upvotes: 1

Related Questions