Page 1 of 1

ERROR db2_bind_param

Posted: Thu Apr 18, 2019 4:07 am
by ushiday
Description:
-------------
PHP Version 7.2.15
Zend Server 2018.0.3 for IBMi
Module Name: ibm_db2
Module release: 2.0.6-zs1

Running db2_exec with db2_bind_param causes an error.
It proved to succeed for global scoped variables but fails for local scoped variables.

I compiled the latest ibm_db2 module (2.0.8) on Zend Server 9.
This problem does not occur with ZendServer9, which is bundled with PHP 7.1.
From this, I can guess that it is not a problem specific to the ibm_db2 module.

This occurs with the following code.

Error message
-------------
Warning: db2_execute(): Value Not Bound in bind_bug_test.php on line 42
Warning: db2_execute(): Binding Error 3 in bind_bug_test.php on line 42
Warning: db2_fetch_assoc(): Fetch Failure in bind_bug_test.php on line 44

Test code
-----------------
bind_bug_test.php
-----------------

Code: Select all

<?php
header('Content-type:text/html;charset=UTF-8');
//Global scoped variables ** SUCCESS **
$db = db2_connect("*LOCLA" ,"USER" ,"PWD" );
$sql="select code from phpdemo.empl where code = ?";
$result = db2_prepare($db,$sql);
$code1 = 555 ;
db2_bind_param($result ,1 ,"code1",DB2_PARAM_IN);
$stmt = db2_execute($result) ;
$row1 = db2_fetch_assoc($result) ;
db2_close($db);
var_dump($row1);
//Local scoped variables ** ERROR **
print '<hr>' ;
$hoge = new Hoge();
$row2 = $hoge->getRow();
var_dump($row2);
class Hoge {
    public function getRow(){
        $db = db2_connect("*LOCLA" ,"USER" ,"PWD" );
        $sql="select * from phpdemo.empl where code = ?";
        $result = db2_prepare($db,$sql);
        $code2 = 110 ;
        db2_bind_param($result ,1 ,"code2",DB2_PARAM_IN);
        $stmt = db2_execute($result) ;
        $row = db2_fetch_assoc($result) ;
        db2_close($db);
        return $row ;
    }
}
?>
Module code
-----------------
ibm_db2.c
-----------------
I think the following part of "ibm_db2.c" is not working properly.

Code: Select all

static int _php_db2_hash_find_ind(char * varname, int varlen, zval **temp, zval ***bind_data, zend_array ** symbol_table_used TSRMLS_DC)
{
    int rc = FAILURE;
    zend_array * symbol_table_local; /* php 5.3+, php 7+ */

#if PHP_MAJOR_VERSION >= 7
    /* Fetch data from symbol table (local scope) */
    symbol_table_local = zend_rebuild_symbol_table();
    *temp =  zend_hash_str_find_ind(symbol_table_local, varname, varlen );
/****** PHP 7.2 gets NULL here! *******/
    if (*temp != NULL) {
        *bind_data = temp;
        *symbol_table_used = symbol_table_local;
        rc = SUCCESS;
    /* Fetch data from symbol table (global scope ... mmm??) */
} else {