yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Binding variable with ociType SQLT_NTY gets cleared #133

Closed cwoodrgr closed 8 months ago

cwoodrgr commented 8 months ago

Summary of problem or feature request

I found issues #73 and #74 when attempting to bind an array to pass to a stored procedure. I followed the example in #74 and found that I was having the same issue where my variable that was being bound was being cleared out.

After looking through some of the PHP documentation and this package, I found the potential issue.

It looks like the fix implemented in #74 is doing a check if the variable is equal to 'OCI-COLLECTION'; however, as of php 8, the class name has been changed to: 'OCICollection'.

PHP OCI Collection

Code snippet of problem

Existing code in Statement.php

case SQLT_NTY:
                $ociType = SQLT_NTY;

                $schema = $options['schema'] ?? '';
                $type_name = $options['type_name'] ?? '';

                if (strtoupper(get_class($variable)) == 'OCI-COLLECTION') {
                    $collection_temp = $this->connection->getNewCollection($type_name, $schema);
                    $collection_temp->assign($variable);

                    $variable = $this->connection->getNewCollection($type_name, $schema);
                    $variable->assign($collection_temp);

                    $collection_temp->free();
                } else {
                    // set params required to use custom type.
                    $variable = $this->connection->getNewCollection($type_name, $schema);
                }
                break;

Changed code in Statement.php on line 326

    if (strtoupper(get_class($variable)) == 'OCICOLLECTION') {

After I removed the hyphen from 'OCICOLLECTION', the bind was no longer reset and I was able to successfully call my stored procedure.

System details

yajra commented 8 months ago

@cwoodrgr thanks for pointing and taking the time to figure this out. Would you mind sending a PR? Thanks!

yajra commented 8 months ago

fixed via #134

cwoodrgr commented 8 months ago

Thank you @yajra