Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number columns are being converted to strings when using oci8 #5

Open
wmiguellima opened this issue Jan 11, 2023 · 2 comments
Open

Comments

@wmiguellima
Copy link

wmiguellima commented Jan 11, 2023

Description

The following code:

$conn = oci_connect('DB', 'PASSWORD', '172.17.0.1:51521/XEPDB1');

if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT * FROM table');
oci_execute($stid);

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    foreach ($row as $item) {
      echo gettype($item) . ' | ';
    }
}

Resulted in this output:

string | object | string |

But I expected this output instead:

integer | object | integer |

Problem:

The integer columns are being converted to strings.

Using CAST is not an option.

Possible solution:

Something like PDO::ATTR_STRINGIFY_FETCHES available on de sqlserver pdo

PHP Version

PHP 8.1

Operating System

Ubuntu 20.04

@wmiguellima wmiguellima added the bug Something isn't working label Jan 11, 2023
@cmb69
Copy link
Member

cmb69 commented Jan 12, 2023

While the documentation doesn't appear to clarify this, I don't think that returning strings for numeric column values qualifies as bug. E.g. there is fetch.phpt which actually expects strings in this case. Furthermore, changing the behavior in stable versions might cause more harm than good (besides that values which would exceed PHP's int range would still need to be returned as strings).

So I'm changing this to feature request, although transferring to doc-en might be the more sensible thing to do.

@cmb69 cmb69 removed the bug Something isn't working label Jan 12, 2023
@flavio-alves-roboyo
Copy link

flavio-alves-roboyo commented Mar 11, 2023

Just to give more context, we have an application that works flawlessly with MySQL/MariaDB/SQL Server, thanks to Laravel Eloquent ORM and no usage of specific syntax. We are trying to add support to Oracle (21c) and right now this is the only thing that is preventing us to do that. The code base is huge, so it is unfeasible to cast the applicable values.

What about create an option, like @wmiguellima proposes, to opt-in for number columns as int (sure, as long as the value doesn't exceeed PHP's int range)?

@derickr derickr transferred this issue from php/php-src Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants