Description:
------------
There is a problem with scope when using db2_bind_param(). db2_bind_param should look up "variable-name" in the scope in which db2_bind_param has been called. It should NOT attempt to look up in the global scope. If it finds a variable in scope with the correct name it should take a _reference_ to that variable. Thus when db2_execute is called it will use a reference to the scope.
The fix in bug #6528 fixes the specific scenario reported but it does not fix the myriad other possible scope issues. It also breaks the design of PHP. Global variables are not part of the local scope in a php function unless explicitly imported. There are absolutely no other cases of PHP global variables "bleeding through" into local scope like this. In addition other cases are not addressed by this
design:
1. calling db2_bind_param() in one function but then calling db2_execute() in another function.
2. Calling db2_bind_param() in a function but performing db2_execute() in the global scope.
This bug is found when we implement this function in IBM P8 PHP engine:
http://www.projectzero.org/bugzilla/show_bug.cgi?id=9279
Reproduce code:
---------------
<?php
function sample_db2_bind_param($conn) {
$sql = "SELECT RTRIM(name) FROM animals WHERE breed = ? ORDER BY id";
$stmt = db2_prepare( $conn, $sql );
// bind variable in local scope
$var = "cat";
db2_bind_param($stmt, 1, "var", DB2_PARAM_IN);
return $stmt;
}
$conn = db2_connect($database, $user, $password);
$stmt = sample_db2_bind_param($conn);
db2_execute($stmt);
$row = db2_fetch_array($stmt);
var_dump($row);
?>
Expected result:
----------------
array(1) {
[0]=>
string(4) "Pook"
}
Actual result:
--------------
Warning: db2_execute(): Value Not Bound in %s\test_sMash_9279_bindings_params.php on line %d
Warning: db2_execute(): Binding Error 3 in %s\test_sMash_9279_bindings_params.php on line %d
Warning: db2_fetch_array(): Fetch Failure in %s\test_sMash_9279_bindings_params.php on line %d
bool(false)

Sorry, but your problem does not imply a bug in PECL itself. For a
list of more appropriate places to ask for help using PECL, please
visit http://pecl.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.
Thank you for your interest in PECL.
Hi,
There is a issue with scope of variable ($var) in your script. For case 1 and 2, scope of $var is only inside sample_db2_bind_param() and is not available inside main script or checked_db2_execute() function.
So, for case 1 you need to define $var in checked_db2_execute() function (before calling db2_execute() function).
And for case 2, define $var before calling db2_execute() function (as you have done in case 3).
Regards,
Ambrish Bhargava