|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2017-01-04 13:25 UTC] ml at menten dot com
 Description:
------------
Hi,
we have a problem with the behaviour of the db2_pclose function on in the 5.6 PHP versions (ZendServer on ibm i).
If i open a persistent connection with db2_pconnect and then close it with db2_pclose, i should normally be able to open/use this connection with db2_pconnect again. In 5.6 PHP i can not re-open the connection with a db2_pconnect, when i have closed it with db2_pclose before. 
The only difference i see in the configuration of our server is that the PHP 5.6 use the release 1.9.9 of the ibm_db2 module.
Best Regards
Michael Linden
Test script:
---------------
<?php
	// Config
	$password = "demo";
	$username = "demo";
	$database = "ieffect";
	
    // Verbindungsaufbau
    $conn_option = array(
        'i5_naming' => DB2_I5_NAMING_ON
    );
    $connection = db2_connect("*LOCAL", $username, $password, $conn_option);
	var_dump(db2_close($connection));
	$connection = db2_pconnect("*LOCAL", $username, $password, $conn_option);
    // Fehlermeldungen
    if (db2_conn_errormsg()) {
        var_dump(db2_conn_errormsg());
        
    } else { // no error
	
		$query = "SELECT * from ieffect/modcfg";
		$params = array();
		$prepQuery = @db2_prepare($connection, $query);
		// prepare error
		if (db2_stmt_errormsg())
		{
			var_dump(db2_stmt_errormsg());
		}
		else
		{
			// execute query
			$result = @db2_execute($prepQuery, $params);
		
		
			if (db2_stmt_errormsg()) {
			
				var_dump(db2_stmt_errormsg());
			
			} else {
			
				$row = db2_fetch_assoc($prepQuery);
			
			
				var_dump($row);
			
			
				var_dump(db2_pclose($connection));
			}
		}
	}
?>
Expected result:
----------------
The second run of the script should be without an error.
Actual result:
--------------
Error message when i try to open the persitent connection again.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
BTW -- bad programming in script ... $query = "SELECT * from ieffect/modcfg" $params = array(); $prepQuery = @db2_prepare($connection, $query); $result = @db2_execute($prepQuery, $params); There are NO parameter markers (?) in the query. For example: $query = "SELECT * from ieffect/modcfg where bunnies=?" $params = array('clouds'); $prepQuery = @db2_prepare($connection, $query); $result = @db2_execute($prepQuery, $params);Well ... still seems to work ok for me ... I do not have your data set, of course,so it could be something data specific. However my test would indicate problem is not connect/close (unless something weird on your system). Anyway, best course of action is likely the trace libdb400.a. bash-4.3$ php execute_array_parms.php try connect first ... array(4) { [0]=> int(0) [1]=> string(3) "cat" [2]=> string(16) "Pook " [3]=> string(4) "3.20" } try pconnect second ... array(4) { [0]=> int(0) [1]=> string(3) "cat" [2]=> string(16) "Pook " [3]=> string(4) "3.20" } bash-4.3$ cat execute_array_parms.php <?php require_once('connection.inc'); echo "try connect first ...\n"; $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $conn_option = array('i5_naming' => DB2_I5_NAMING_ON); $conn = db2_connect($database, $user, $password); if ($conn) { $stmt = db2_prepare( $conn, $sql); if (db2_execute($stmt, array(0, 'Pook'))) { while ($row = db2_fetch_array($stmt)) { var_dump($row); } } } else { echo "Connection failed.\n"; } $rc = db2_close($conn); echo "try pconnect second ...\n"; $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $conn = db2_pconnect($database, $user, $password); if ($conn) { $stmt = db2_prepare( $conn, $sql); if (db2_execute($stmt, array(0, 'Pook'))) { while ($row = db2_fetch_array($stmt)) { var_dump($row); } } } else { echo "Connection failed.\n"; } ?>Also seems to work with db2_fetch_assoc (closer to your data set??). bash-4.3$ php execute_array_parms.php try connect first ... array(4) { ["ID"]=> int(0) ["BREED"]=> string(3) "cat" ["NAME"]=> string(16) "Pook " ["WEIGHT"]=> string(4) "3.20" } try pconnect second ... array(4) { ["ID"]=> int(0) ["BREED"]=> string(3) "cat" ["NAME"]=> string(16) "Pook " ["WEIGHT"]=> string(4) "3.20" } bash-4.3$ cat execute_array_parms.php <?php require_once('connection.inc'); echo "try connect first ...\n"; $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $conn_option = array('i5_naming' => DB2_I5_NAMING_ON); $conn = db2_connect($database, $user, $password); if ($conn) { $stmt = db2_prepare( $conn, $sql); if (db2_execute($stmt, array(0, 'Pook'))) { while ($row = db2_fetch_assoc($stmt)) { var_dump($row); } } } else { echo "Connection failed.\n"; } $rc = db2_close($conn); echo "try pconnect second ...\n"; $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $conn = db2_pconnect($database, $user, $password); if ($conn) { $stmt = db2_prepare( $conn, $sql); if (db2_execute($stmt, array(0, 'Pook'))) { while ($row = db2_fetch_assoc($stmt)) { var_dump($row); } } } else { echo "Connection failed.\n"; } ?> bash-4.3$Here is another test with more calls to 'errmsg' ... bash-4.3$ php connect_close_pconnect.php === version === required version = 1.9.9-zs4 actual version (this) = 1.9.9-zs4 === db2_connect === db2_connect = Resource id #5 db2_conn_errormsg = db2_prepare (Resource id #6) = db2_execute (Resource id #6) = array(4) { ["ID"]=> int(0) ["BREED"]=> string(3) "cat" ["NAME"]=> string(16) "Pook " ["WEIGHT"]=> string(4) "3.20" } db2_fetch_assoc = db2_close = 1 db2_conn_errormsg = test - I am working ok! actual - I am working ok! === db2_pconnect === db2_pconnect = Resource id #7 db2_conn_errormsg = test - I am working ok! I am working ok! db2_prepare (Resource id #8) = db2_execute (Resource id #8) = array(4) { ["ID"]=> int(0) ["BREED"]=> string(3) "cat" ["NAME"]=> string(16) "Pook " ["WEIGHT"]=> string(4) "3.20" } db2_fetch_assoc = bash-4.3$ cat connect_close_pconnect.php <?php require_once('connection.inc'); echo("=== version ===\n"); echo("required version = 1.9.9-zs4\nactual version (this) = ".phpversion('ibm_db2')."\n"); // Verbindungsaufbau echo("=== db2_connect ===\n"); $conn_option = array('i5_naming' => DB2_I5_NAMING_ON); $conn = db2_connect("*LOCAL", $username, $password, $conn_option); //$conn = db2_connect("*LOCAL", $username, $password); echo("db2_connect = ".$conn."\n"); echo("db2_conn_errormsg = ".db2_conn_errormsg()."\n"); // run prepare/execute/fetch $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $stmt = db2_prepare( $conn, $sql); echo("db2_prepare ($stmt) = ".db2_stmt_errormsg()."\n"); db2_execute($stmt, array(0, 'Pook')); echo("db2_execute ($stmt) = ".db2_stmt_errormsg()."\n"); while ($row = db2_fetch_assoc($stmt)) { var_dump($row); echo("db2_fetch_assoc = ".db2_stmt_errormsg()."\n"); } // close now please $rc = db2_close($conn); echo("db2_close = ".$rc."\n"); echo("db2_conn_errormsg = ".db2_conn_errormsg()."\n"); // Fehlermeldungen if (db2_conn_errormsg()) echo("test - I am NOT working ok!\n"); else echo("test - I am working ok!\n"); if ($conn) echo("actual - I am working ok!\n"); else die("actual - I am NOT working ok!\n"); echo("=== db2_pconnect ===\n"); $conn = db2_pconnect("*LOCAL", $username, $password, $conn_option); echo("db2_pconnect = ".$conn."\n"); echo("db2_conn_errormsg = ".db2_conn_errormsg()."\n"); // Fehlermeldungen if (db2_conn_errormsg()) echo("test - I am NOT working ok!\n"); else echo("test - I am working ok!\n"); if ($conn) echo("I am working ok!\n"); else die("I am NOT working ok!\n"); // run prepare/execute/fetch $sql = "SELECT id, breed, name, weight FROM $user.animals WHERE id = ? AND name = ?"; $stmt = db2_prepare( $conn, $sql); echo("db2_prepare ($stmt) = ".db2_stmt_errormsg()."\n"); db2_execute($stmt, array(0, 'Pook')); echo("db2_execute ($stmt) = ".db2_stmt_errormsg()."\n"); while ($row = db2_fetch_assoc($stmt)) { var_dump($row); echo("db2_fetch_assoc = ".db2_stmt_errormsg()."\n"); } ?> bash-4.3$Ops. Sorry. My fault. I see connect/close issue running from the web, but not command line. I will look into the problem and post a fix to YIPs test versions. (Man, holiday removed my customer 'i meant to say' intuition radar). === version === required version = 1.9.9-zs4 actual version (this) = 1.9.9-zs1 === db2_connect === db2_connect = Resource id #1 db2_conn_errormsg = db2_prepare (Resource id #2) = db2_execute (Resource id #2) = array(4) { ["ID"]=> int(0) ["BREED"]=> string(3) "cat" ["NAME"]=> string(16) "Pook " ["WEIGHT"]=> string(4) "3.20" } db2_fetch_assoc = db2_close = 1 db2_conn_errormsg = test - I am working ok! actual - I am working ok! === db2_pconnect === db2_pconnect = Resource id #3 db2_conn_errormsg = test - I am working ok! I am working ok! Warning: db2_prepare(): Statement Prepare Failed in /www/zendsvr6/htdocs/connect_close_pconnect.php on line 42 db2_prepare () = Warning: db2_execute() expects parameter 1 to be resource, boolean given in /www/zendsvr6/htdocs/connect_close_pconnect.php on line 44 db2_execute () = Warning: db2_fetch_assoc() expects parameter 1 to be resource, boolean given in /www/zendsvr6/htdocs/connect_close_pconnect.php on line 46 db2_pclose = 1 db2_pclose =Ok. Found problem (PHP 7 port helpers ... not me). I will post a new binary 1.9.9-zs5 to yips soon. I added the following comment to ibm_db2.c code. #ifdef PASE /* db2_pclose - last ditch persistent close, but reuse zend hash * Note: Do not move this code, someone broke IBM i 1.9.9 */ if (endpconnect) { conn_res->hdbc = 0; conn_res->flag_pconnect=9; } #endif /* PASE */