php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #56784 scoping problem in db2_bind_param
Submitted: 2006-01-19 10:32 UTC Modified: 2006-03-03 15:18 UTC
From: james dot jones at firstinvestors dot com Assigned:
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.1.1 OS: Redhat Linux ES 2.1
Private report: No CVE-ID: None
 [2006-01-19 10:32 UTC] james dot jones at firstinvestors dot com
Description:
------------
There is a problem with scope when using db2_bind_param. See code samples. Version (1) works because everything is in the same scope. Version (2) does not work because $var is in the wrong scope. We can bring $var into scope using a 'global' declaration, and there are various other ways to force it to work generally (e.g., passing an array of variable names to the function and copying them into local scope).

But should this even be necessary? I would *expect* version (2) to work without all this rigmarole. Is it possible to save scoping info when db2_bind_param is called, so that this can be used to retrieve the value of the variable when db2_execute is called?

Reproduce code:
---------------
Version 1 (works OK):

<?php
$var = 'test';
db2_bind_param($query, 1, 'var');
db2_execute($conn, $query);
?>

Version 2 (doesn't work):

<?php
function checked_db2_execute($query, $params = NULL) {
  $rc = @db2_execute($GLOBALS['conn'], $query);
  if(!$rc) { // standard error-handling
  }
}
$var = 'test';
db2_bind_param($query, 1, 'var');
checked_db2_execute($conn, $query);
?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-03 15:18 UTC] kfbombar at us dot ibm dot com
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

Thanks James for the bug report and working with ibm_db2.  You are correct in your thoughts that it should be more simple.  We have made the changes necessary for your test cases to work.  Let us know if we can be of any more assistance.  Thanks again James.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 16 23:01:27 2019 UTC