PDO_OCI returns NULL on INSERT...RETURNING operations in PHP 8.2 - #4617
PDO_OCI returns NULL on INSERT...RETURNING operations in PHP 8.2#4617andreaepifani-afk wants to merge 4 commits into
Conversation
Forced $returnID to integer.
|
I understand this fixed the issue in your application, but the fix itself looks like a workaround for a bug somewhere. Based on your information I cannot judge if this is a framework issue or part of the environment (application code, specific Oracle, PHP and driver versions). To judge that we would need a reproducable example of the bug you encountered and/or insight into the exact root cause for which component update exactly caused a regression. |
|
Hi @marcovtwout , To isolate the issue from my specific application, I created a clean project using ./yiic webapp test-oci and performed the following steps:
I have identified that the bug is located in COciCommandBuilder, specifically regarding how returnID is handled during the binding process. |
Fixed a random 503 Service Unavailable crash on PHP 8.2 caused by the previous fix. Following Yii2 strategies, the RETURNING INTO clause was removed from INSERT statements in PDO_OCI. The last insert ID is now safely retrieved via a separate sequence_name.CURRVAL query.
|
Thanks for looking further into it :) I'm not sure the actual bug is in the framework code, it looks like the call to $command->bindParam() is done correctly, passing PDO::PARAM_INT as the explicit parameter type: https://github.com/yiisoft/yii/blob/master/framework/db/schema/oci/COciCommandBuilder.php#L112 Since you now have a reproducable test case, could you test further to see where the regression starts, ie. which version of PHP or PDO_OCI exactly breaks the update? And which version of Oracle Database on which platform are you using? |
|
Update: I think the bug is in the PDO_OCI library, this looks very similar to your report: php/pecl-database-pdo_oci#26 |
|
Hi have alredy testing with pdo: ` $stmt->bindParam(':id', $id, PDO::PARAM_INT, 12); $stmt->execute(); this code, similar at yii1 implementation, the id return NULL. I updated my PR with commit that remove RETURNING INTO clause. |
clean code
implement method getTableSequenceName to retrieve the correct sequence name of table.
|
@andreaepifani-afk That confirms the source of the issue is not in the Yii framework but in PHP / PHP-OCI. It's not yet clear to me which version/change exactly broke the previous behavior, that would help to understand it better. I suggest to investigate that further through php/pecl-database-pdo_oci#26 and once more info comes back we can see if there's anything we should do here. |
|
The problem is that OCI, in many operations, returns |
|
@terabytesoftw You are saying this issue is actually about a deprecation warning and not about a regression since a specific PHP/OCI update? Where exactly in our framework is the deprecation warning triggered? |
|
If the error occurs in a function such as Also, sometimes PDO varies according to the PHP version, and the problem must be resolved somehow. btw I'll try this on Yii2. |
A critical issue encountered when migrating from PHP 7.3 to PHP 8.2 using the PDO_OCI driver with Oracle database.
After migrating from PHP 7.3.20, the application stopped functioning correctly. Whenever a new record was created in Oracle, the RETURNING INTO clause failed to populate the ID reference, returning NULL instead. I fixed this by explicitly casting the variable to an integer to ensure proper binding in the PHP 8 environment.
Forced $this->returnID = 0; immediately before bindParam to ensure a clean integer memory buffer is allocated.
Tested with php 8.2.28 and work fine, backward compatibility maintained.