|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-03-03 15:18 UTC] kfbombar at us dot ibm dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 07:00:02 2025 UTC |
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); ?>