|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-07-26 15:10 UTC] aaron dot hawley at vtinfo dot com
Description: ------------ This is a follow-up to bug #17004. Shouldn't db2_bind_param be usable from within a function using variables within the function's scope as long as db2_prepare and db2_execute are also in the same scope? I am using version 1.8.3 that comes with Zend Server 5.0.1 for IBM i. PHP version is 5.3.1. Thanks. Reproduce code: --------------- <?php require_once('connection.inc'); class IbmDb2_Test000 { public function m() { if ($conn) { $conn = db2_connect($database, $user, $password); $sql = 'CALL match_animal(?, ?, ?)'; $stmt = db2_prepare($conn, $sql); $name = "Peaches"; $second_name = "Rickety Ride"; $weight = 0; db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT); db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT); print "Values of bound parameters _before_ CALL:\n"; print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n"; if (db2_execute($stmt)) { print "Values of bound parameters _after_ CALL:\n"; print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n"; print "Results:\n"; while ($row = db2_fetch_array($stmt)) { print " " . trim($row[0]) . ", " . trim($row[1]) . ", {$row[2]}\n"; } } db2_rollback($conn); } } } IbmDb2_Test000::m(); ?> Expected result: ---------------- Values of bound parameters _before_ CALL: 1: Peaches 2: Rickety Ride 3: 0 Values of bound parameters _after_ CALL: 1: Peaches 2: TRUE 3: 12 Results: Peaches, dog, 12.30 Pook, cat, 3.20 Rickety Ride, goat, 9.70 Smarty, horse, 350.00 Sweater, llama, 150.00 Actual result: -------------- PHP Warning: db2_execute(): Value Not Bound in test_000_BindParamScope.php on line 25 PHP Warning: db2_execute(): Binding Error 3 in test_000_BindParamScope.php on line 25 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
Hi, I am not sure how your test case is working. Here is a snippet from the sample provided by you: >>> if ($conn) { $conn = db2_connect($database, $user, $password); ..... } <<< In above case, you are checking $conn, which is not yet initialized and then creating the connection. Ideally, you should create connection first and then check the condition. I modified the test case and it is working fine. Here is the modified test case: <?php require_once('connection.inc'); class IbmDb2_Test000 { public function m() { $conn = db2_connect($database, $user, $password); if ($conn) { $sql = 'CALL match_animal(?, ?, ?)'; $stmt = db2_prepare($conn, $sql); $name = "Peaches"; $second_name = "Rickety Ride"; $weight = 0; db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT); db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT); print "Values of bound parameters _before_ CALL:\n"; print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n"; if (db2_execute($stmt)) { print "Values of bound parameters _after_ CALL:\n"; print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n"; print "Results:\n"; while ($row = db2_fetch_array($stmt)) { print " " . trim($row[0]) . ", " . trim($row[1]) . ", {$row[2]}\n"; } } db2_rollback($conn); } } } IbmDb2_Test000::m(); ?> Regards, Ambrish Bhargava