php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57135 Opening extra persistent connection breaks unrelated code
Submitted: 2006-07-11 14:59 UTC Modified: 2006-09-22 11:27 UTC
From: jtray at us dot ibm dot com Assigned:
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.1.2 OS: Windows XP Pro SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jtray at us dot ibm dot com
New email:
PHP Version: OS:

 

 [2006-07-11 14:59 UTC] jtray at us dot ibm dot com
Description:
------------
Working code stops working when a db2_pconnect() call is made in the middle, even though the return value from db2_pconnect() is not used at all.  db2_pconnect() seems to have side effects that break unrelated calls.

ibm_db2 DLL from here:
http://pecl4win.php.net/download.php/ext/5_1/5.1.2/php_ibm_db2.dll
I think it is version 1.2.3

DB2 version info:
DB2 administration tools level:
Product identifier           SQL08023
Level identifier             03040106
Level                        DB2 v8.1.10.812
Build level                  s050811
PTF                          WR21362


Reproduce code:
---------------
<?php

include_once '../private/rb.include';

print '<html><pre>';

try {
  $db = db2_pconnect(RB_DATABASE, RB_USERID, RB_PASSWORD, 
		     array("autocommit" => DB2_AUTOCOMMIT_OFF));
  if ($db === false)
    throw new Exception("db2_pconnect failed");
  var_dump($db);

  $pstmt = db2_prepare($db, 'select * from bug');
  if ($pstmt === false)
    throw new Exception("db2_prepare failed; error = " 
			. db2_stmt_errormsg($pstmt));

  $success = db2_execute($pstmt);
  if (!$success)
    throw new Exception("db2_execute failed; error = " 
			. db2_stmt_errormsg($pstmt));

  print '</br>BUG table contents:</br>';

  $row = db2_fetch_row($pstmt);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt, 'FOO');
  var_dump($value);

  $row = db2_fetch_row($pstmt);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt, 'FOO');
  var_dump($value);

  //===============

  $pstmt2 = db2_prepare($db, 'select * from test');
  if ($pstmt2 === false)
    throw new Exception("db2_prepare failed; error = " 
			. db2_stmt_errormsg($pstmt2));
  $success = db2_execute($pstmt2);
  if (!$success)
    throw new Exception("db2_execute failed; error = " 
			. db2_stmt_errormsg($pstmt2));

  print '</br>TEST table contents:</br>';

  $row = db2_fetch_row($pstmt2);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt2, 'BAR');
  var_dump($value);

  $row = db2_fetch_row($pstmt2);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt2, 'BAR');
  var_dump($value);

  //===============

  print '</br>';

  $pstmt3 = db2_prepare($db, 'select * from bug');
  if ($pstmt3 === false)
    throw new Exception("db2_prepare failed; error = " 
			. db2_stmt_errormsg($pstmt3));

  $success = db2_execute($pstmt3);
  if (!$success)
    throw new Exception("db2_execute failed; error = " 
			. db2_stmt_errormsg($pstmt3));

  $row = db2_fetch_row($pstmt3);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt3, 'FOO');
  print 'From BUG table:</br>';
  var_dump($value);

  if (true) {
    print 'Opening second persistent connection...</br>';
  
    $db2 = db2_pconnect(RB_DATABASE, RB_USERID, RB_PASSWORD, 
			array("autocommit" => DB2_AUTOCOMMIT_OFF));
    if ($db2 === false)
      throw new Exception("db2_pconnect failed");
    var_dump($db2);
  }

  $pstmt4 = db2_prepare($db, 'select * from test');
  if ($pstmt4 === false)
    throw new Exception("db2_prepare failed; error = " 
			. db2_stmt_errormsg($pstmt4));

  $success = db2_execute($pstmt4);
  if (!$success)
    throw new Exception("db2_execute failed; error = " 
			. db2_stmt_errormsg($pstmt4));

  $row = db2_fetch_row($pstmt4);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt4, 'BAR');
  print 'From TEST table:</br>';
  var_dump($value);

  $row = db2_fetch_row($pstmt4);
  if ($row === false) 
    throw new Exception('No data');
  $value = db2_result($pstmt4, 'BAR');
  print 'From TEST table:</br>';
  var_dump($value);

  $row = db2_fetch_row($pstmt3);
  if ($row === false) 
    throw new Exception('BAR table is out of data');
  $value = db2_result($pstmt3, 'FOO');
  print 'From BUG table:</br>';
  var_dump($value);

  db2_commit($db);
  db2_commit($db);
}
catch (Exception $e) {
  db2_rollback($db);
  print $e->__toString();
}

print '</pre></html>';

?>


Expected result:
----------------
If line 89 is "  if (false) {":

resource(5) of type (DB2 Persistent Connection)

BUG table contents:
string(6) "hi mom"
string(13) "testing 1 2 3"

TEST table contents:
string(12) "hello, world"
string(14) "open other end"

From BUG table:
string(6) "hi mom"
From TEST table:
string(12) "hello, world"
From TEST table:
string(14) "open other end"
From BUG table:
string(13) "testing 1 2 3"


Actual result:
--------------
If line 89 is "  if (true) {":

resource(5) of type (DB2 Persistent Connection)

BUG table contents:
string(6) "hi mom"
string(13) "testing 1 2 3"

TEST table contents:
string(12) "hello, world"
string(14) "open other end"

From BUG table:
string(6) "hi mom"
Opening second persistent connection...
resource(9) of type (DB2 Persistent Connection)
From TEST table:
string(12) "hello, world"
From TEST table:
string(14) "open other end"
exception 'Exception' with message 'BAR table is out of data' in C:\u\jtray\cvs\rb\js\public\bug2.php:126
Stack trace:
#0 {main}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-13 11:17 UTC] kfbombar at us dot ibm dot com
I have not been able to reproduce this issue.  I am using the script below to try and repro.  Can you provide a more simple script that we can copy directly in our systems to try and reproduce?  Thank you.

<?php

  $db = db2_pconnect('sample', 'user', 'pass');
  if ($db) {
	$pstmt = db2_prepare($db, 'select * from animals');
	$success = db2_execute($pstmt);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);

	$pstmt = db2_prepare($db, 'select * from animals');
	$success = db2_execute($pstmt);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);

	$pstmt = db2_prepare($db, 'select * from animals');
	$success = db2_execute($pstmt);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);

        $db_other = db2_pconnect('sample', 'user', 'pass');

	$pstmt = db2_prepare($db, 'select * from animals');
	$success = db2_execute($pstmt);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);
	$row = db2_fetch_row($pstmt);
	$value = db2_result($pstmt, 'BREED');
	var_dump($value);

  } else {
    print "Not connected\n";
  }

?>
 [2006-07-14 12:05 UTC] jtray at us dot ibm dot com
Here is a stripped-down version of the original testcase.  Each table (BUG and TEST) has two rows.  If line 19 is "if (true)", it fails with this message:

exception 'Exception' with message 'BUG table is out of data' in C:\u\jtray\cvs\rb\js\public\bug2s.php:45

If line 19 is "if (false)", it does not fail.

I suspect your testcase works because you do the prepare/execute after the second pconnection is opened, and I do it before.

<?php

include_once '../private/rb.include';

print '<html><pre>';

try {
  $db = db2_pconnect(RB_DATABASE, RB_USERID, RB_PASSWORD, 
		     array("autocommit" => DB2_AUTOCOMMIT_OFF));
  $pstmt3 = db2_prepare($db, 'select * from bug');
  $success = db2_execute($pstmt3);
  $row = db2_fetch_row($pstmt3);
  $value = db2_result($pstmt3, 'FOO');
  print 'From BUG table:</br>';
  var_dump($value);

  if (true) {
    print 'Opening second persistent connection...</br>';
  
    $db2 = db2_pconnect(RB_DATABASE, RB_USERID, RB_PASSWORD, 
			array("autocommit" => DB2_AUTOCOMMIT_OFF));
  }

  $pstmt4 = db2_prepare($db, 'select * from test');
  $success = db2_execute($pstmt4);
  $row = db2_fetch_row($pstmt4);
  if ($row === false) 
    throw new Exception('No data');
  
  $value = db2_result($pstmt4, 'BAR');
  print 'From TEST table:</br>';
  var_dump($value);

  $row = db2_fetch_row($pstmt4);
  if ($row === false) 
    throw new Exception('No data');
  $value = db2_result($pstmt4, 'BAR');
  print 'From TEST table:</br>';
  var_dump($value);

  $row = db2_fetch_row($pstmt3);
  if ($row === false) 
    throw new Exception('BUG table is out of data');
  $value = db2_result($pstmt3, 'FOO');
  print 'From BUG table:</br>';
  var_dump($value);

  db2_commit($db);
}
catch (Exception $e) {
  db2_rollback($db);
  print $e->__toString();
}

print '</pre></html>';

?>
 [2006-07-19 11:18 UTC] kfbombar at us dot ibm dot com
I have run the following script (directly based off of your stripped down reproducable code):

<?php

try {
  $db = db2_pconnect('sample', 'user', 'pass',
             array("autocommit" => DB2_AUTOCOMMIT_OFF));
  $pstmt3 = db2_prepare($db, 'select * from animals');
  $success = db2_execute($pstmt3);
  $row = db2_fetch_row($pstmt3);
  $value = db2_result($pstmt3, 'BREED');
  print "From BUG table:\n";
  var_dump($value);

  if (true) {
    print "Opening second persistent connection...\n";

    $db2 = db2_pconnect('sample', 'user', 'pass',
            array("autocommit" => DB2_AUTOCOMMIT_OFF));
  }

  $pstmt4 = db2_prepare($db, 'select * from animals');
  $success = db2_execute($pstmt4);
  $row = db2_fetch_row($pstmt4);
  if ($row === false)
    throw new Exception('No data');

  $value = db2_result($pstmt4, 'BREED');
  print "From TEST table:\n";
  var_dump($value);

  $row = db2_fetch_row($pstmt4);
  if ($row === false)
    throw new Exception('No data');
  $value = db2_result($pstmt4, 'BREED');
  print "From TEST table:\n";
  var_dump($value);

  $row = db2_fetch_row($pstmt3);
  if ($row === false)
    throw new Exception('BUG table is out of data');
  $value = db2_result($pstmt3, 'BREED');
  print "From BUG table:\n";
  var_dump($value);

  db2_commit($db);
}
catch (Exception $e) {
  db2_rollback($db);
  print $e->__toString();
}

?>

When the "if" is set to true, the following is produced:

From BUG table:
string(3) "cat"
Opening second persistent connection...
From TEST table:
string(3) "cat"
From TEST table:
string(3) "dog"
From BUG table:
string(3) "dog"

When the "if" is set to false, the following is produced:

From BUG table:
string(3) "cat"
From TEST table:
string(3) "cat"
From TEST table:
string(3) "dog"
From BUG table:
string(3) "dog"

Please inform on how we can reproduce.
 [2006-09-22 11:27 UTC] kfbombar at us dot ibm dot com
65 days since last feedback.  Closing until more information provided.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 21:01:25 2019 UTC