php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59322 Allow local scope with db2
Submitted: 2010-07-26 15:10 UTC Modified: 2010-11-26 00:35 UTC
From: aaron dot hawley at vtinfo dot com Assigned:
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.3.1 OS: i5/OS
Private report: No CVE-ID: None
 [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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-27 14:08 UTC] aaron dot hawley at vtinfo dot com
Our version of IBM i is v5R4.
 [2010-07-28 05:55 UTC] abhargav at in dot ibm dot com
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
 [2010-07-28 08:56 UTC] aaron dot hawley at vtinfo dot com
Sorry, that was a typo.  The script still issues the warnings and fails to print anything returned from calling the stored procedure.

Thanks for responding so quickly.  This is a major functionality issue that is severely restricting our progress.
 [2010-07-29 06:21 UTC] abhargav at in dot ibm dot com
Hi,

Can you provide me your client details? Is it running on System i itself or this is running on LUW client?

Regards,
Ambrish Bhargava
 [2010-07-29 10:17 UTC] aaron dot hawley at vtinfo dot com
We are running everything on the IBM i.

Let me know if you need more details.
 [2010-10-19 09:07 UTC] aaron dot hawley at vtinfo dot com
Looks like it might be an issue with PHP 5.3.1 as shipped with Zend Server for IBM i.

"I have been working with a Zend contact (Sam Pinkhasov) on this issue for a few weeks now. I received an email this morning confirming that there is a problem in the ibm_db2 extension under PHP 5.3. Zend is contacting IBM about the issue. This is not a situation where every stored procedure fails under ibm_db2 and PHP 5.3. If you run up against this 'Value Not Bound' message and suspect you've ran into this issue, modify your code and call the procedure using the i5 Toolkit. If it works there but not when using db2 calls, then you've ran into this issue. [...]"

more: http://forums.zend.com/viewtopic.php?f=77&t=6405&start=10

I'm looking into getting the patched (updated?) version of ibm_db2 from Zend.
 [2010-11-03 14:25 UTC] aaron dot hawley at vtinfo dot com
Zend sent me a patched version of ibm_db2.so and it makes db2_bind_param work correctly.  I have no details about whether it is simply just an updated version of ibm_db2 (Zend Server typically lags behind) or it is a patch they have made themselves.  The phpinfo information gives

Module release: 1.9.0
Module revision: $Revision: 297218 $
Binary data mode (ibm_db2.binmode): DB2_BINARY
DB2 instance name (ibm_db2.instance_name): no value
 [2010-11-26 00:35 UTC] abhargav at in dot ibm dot com
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/ibm_db2

Regards,
Ambrish Bhargava
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC