php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74703 db2_execute() inconsistently fails to bind a boolean value
Submitted: 2017-06-07 00:49 UTC Modified: 2018-08-27 10:43 UTC
From: smorozov at sugarcrm dot com Assigned: vnkbabu (profile)
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 7.1.5 OS: CentOS 7, Ubuntu 16.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smorozov at sugarcrm dot com
New email:
PHP Version: OS:

 

 [2017-06-07 00:49 UTC] smorozov at sugarcrm dot com
Description:
------------
The issue is reproducible in the following environment:

1. PHP 7.1(.5), IBM DB2 10.5. Not reproducible on PHP 5.6.30 and PHP 7.0.19 in the exact same environment.
2. A boolean value is bound to an integer column (e.g. a SMALLINT).
3. The boolean value is not a literal but a result of comparison of an array element to a string literal (just comparing strings will not work, see example).
4. The query in question is not the first query executed after connecting to the DB.


Test script:
---------------
/*
CREATE TABLE DB2_TEST
(
    ID smallint DEFAULT 0
)
*/

$dsn = 'HOSTNAME=localhost;UID=db2inst1;PWD=Passw0rd;DATABASE=test';
$conn = db2_connect($dsn, null, null);

if (!$conn) {
    echo db2_conn_errormsg(), PHP_EOL;
    exit(1);
}

printf('PHP: %s' . PHP_EOL, phpversion());
printf('ibm_db2: %s' . PHP_EOL, phpversion('ibm_db2'));
$server = db2_server_info($conn);
printf('DB2 NAME: %s, VERSION: %s' . PHP_EOL, $server->DBMS_NAME, $server->DBMS_VER);

// without executing a query before the following one, the issue is not reproducible
$stmt = db2_prepare($conn, 'SELECT 1 FROM SYSIBM.SYSDUMMY1');
$result = db2_execute($stmt);

if (!$result) {
    echo db2_stmt_errormsg(), PHP_EOL;
    exit(1);
}

// the value of $true is the result of comparison of an array element value
// with the same value. if it's just literal true, the issue is not reproducible
$array = array('key' => 'value');
$true = $array['key'] == 'value';

$stmt = db2_prepare($conn, 'SELECT ID FROM DB2_TEST WHERE ID = ?');
$result = db2_execute($stmt, [$true]);

if (!$result) {
    echo db2_stmt_errormsg(), PHP_EOL;
    exit(1);
}

echo 'OK', PHP_EOL;


Expected result:
----------------
The second call to db2_execute() is expected to return TRUE. OK is displayed.

Actual result:
--------------
[IBM][CLI Driver] CLI0111E  Numeric value out of range. SQLSTATE=22003 SQLCODE=-99999

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-07 00:52 UTC] smorozov at sugarcrm dot com
-Summary: db2_execute fails to bind a boolean value +Summary: db2_execute() inconsistently fails to bind a boolean value
 [2017-06-07 00:52 UTC] smorozov at sugarcrm dot com
Updated the summary to emphasize the inconsistent nature of the issue.
 [2017-06-07 19:53 UTC] smorozov at sugarcrm dot com
-Package: ibm_db2 +Package: opcache
 [2017-06-07 19:53 UTC] smorozov at sugarcrm dot com
Moved the issue from ibm_db2 category to Opcache as it's only reproducible with Opcache enabled.
 [2017-07-19 11:22 UTC] smorozov at sugarcrm dot com
-Package: opcache +Package: ibm_db2
 [2017-07-19 11:22 UTC] smorozov at sugarcrm dot com
Moving back to ibm_db2 based on https://twitter.com/nikita_ppv/status/872548895330578432
 [2017-07-19 11:51 UTC] smorozov at sugarcrm dot com
Surprisingly, the issue is not reproducible on PHP 7.1.7 but is still reproducible on a freshly built PHP 7.1.5:

↪  php test.php
PHP: 7.1.5
ibm_db2: 1.9.9
DB2 NAME: DB2/LINUXX8664, VERSION: 10.05.0005

Warning: db2_execute(): Statement Execute Failed in test.php on line 31

Call Stack:
    0.0002     360968   1. {main}() test.php:0
    0.0494     383384   2. db2_execute() test.php:31

[IBM][CLI Driver] CLI0111E  Numeric value out of range. SQLSTATE=22003 SQLCODE=-99999

↪  php test.php
PHP: 7.1.7
ibm_db2: 1.9.9
DB2 NAME: DB2/LINUXX8664, VERSION: 10.05.0005
OK
 [2018-08-27 10:43 UTC] vnkbabu@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: vnkbabu
 [2018-08-27 10:43 UTC] vnkbabu@php.net
Please try with the latest release and reopen if issue still persist.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:22 2019 UTC