php / php-src

The PHP Interpreter
https://www.php.net
Other
37.93k stars 7.73k forks source link

PDO OCI binds boolean false as NULL #15182

Closed morozov closed 3 weeks ago

morozov commented 1 month ago

Description

The following code:

<?php

$conn = new PDO('oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))', 'system', 'oracle');
$stmt = $conn->prepare('SELECT ?, ? FROM DUAL');
$stmt->bindValue(1, true, PDO::PARAM_BOOL);
$stmt->bindValue(2, false, PDO::PARAM_BOOL);
$stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_NUM));

Resulted in this output:

array(2) {
  [0] =>
  string(1) "1"
  [1] =>
  NULL
}

But I expected this output instead:

array(2) {
  [0] =>
  string(1) "1"
  [1] =>
  string(1) "0"
}

PHP Version

PHP 8.3.8

Operating System

Linux

The issue was originally reported as bug #81586, discovered via https://github.com/doctrine/dbal/issues/2481.

cmb69 commented 1 month ago

Maybe @cjbj knows what's going on there?

mvorisek commented 1 month ago

I guess bool is not supported at all by PDO OCI and bool is converted to string. In PHP, false is converted to empty string (https://3v4l.org/NkDMT). Empty string in Oracle is always converted to null (https://docs.oracle.com/database/121/SQLRF/sql_elements005.htm) by Oracle database.

So this issue seems like a duplicate of https://github.com/php/php-src/issues/12603.

morozov commented 1 month ago

So this issue seems like a duplicate of #12603.

FWIW, it doesn't mention pdo_oci.

SakiTakamachi commented 1 month ago

As already mentioned, pdo_oci does not support PARAM_BOOL and will interpret it as PARAM_STR as a fallback.

Of course it is possible to change it to accommodate PARAM_BOOL, but that cannot be done in a stable version of php.

From 8.4 onwards pdo_oci is unbundled and is now a PECL extension. If there are no objections, perhaps this issue should be forwarded to the oci repository.

github-actions[bot] commented 3 weeks ago

No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you.