Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Memory Leak Issue When Connecting Via DB2 Connect #394

Open
2 tasks done
StoneMorKnight opened this issue Aug 27, 2019 · 1 comment
Open
2 tasks done

Memory Leak Issue When Connecting Via DB2 Connect #394

StoneMorKnight opened this issue Aug 27, 2019 · 1 comment

Comments

@StoneMorKnight
Copy link

Provide a narrative description of what you are trying to accomplish.

There appears to be a memory leak issue when connecting to a DB2 database via the DB2 Connect driver while using the Zend DB package.

OS: Ubuntu 18.04.1 LTS
PHP Version: PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS )
DB2 Connect Version: 11.1

Explanation of Diagnosis:
When I run a similar process with a simple PDO object, I do not get the same memory allocation issues. Here is the PDO code I was using to check:

$conn = new PDO('ibm:MYDEVENV', 'MYUSERNAME', 'MYPASSWORD');
$result = $conn->query('select ACCT_UNIT from MYLIBRARY.MYTABLE where MYVALUE = 113;');
if (!$result) {
	var_dump($conn->errorInfo());
}
while ($row = $result->fetch()) {
	var_dump($row);
}

The outcome is as expected:

array(2) {
  ["ACCT_UNIT"]=>
  string(15) "113            "
  [0]=>
  string(15) "113            "
}

When this database connection and query are run using Zend-Db package, a memory allocation error is thrown. See below:

Code to reproduce the issue

$configArray = array(
    'driver' => 'pdo_ibm',
    'dsn' => 'ibm:MYDEVENV',
    'platform' => 'IbmDb2',
    'platform_options' => [
        'quote_identifiers' => false,
    ],
    'driver_options' => [
        'isDefaultTableAdapter' => true,
        'i5_naming' => 'DB2_I5_NAMING_ON',
        'autocommit' => 'DB_AUTOCOMMIT_OFF',
        'i5_lib' => 'MYLIBRARY'
    ],
    'username' => 'MYUSERNAME',
    'password' => 'MYPASSWORD',
);
$adapter = new \Zend\Db\Adapter\Adapter($configArray);
$sql = 'select ACCT_UNIT from MYLIBRARY.MYTABLE where MYFIELD = :MYVALUE';
$parameters = ['MYVALUE' => 113];
try {
       $result = $adapter->query($sql, $parameters);

       if ($result instanceof ResultSet)
       {
            $arrayResults = $result->toArray();

            if (sizeof($arrayResults) === 1)
                return $arrayResults[0];
            else {
                $arrayResults[] = array('ACCT_UNIT'=>'0000');
                return $arrayResults[0];
             }
        }
} catch (\Exception $e) {
       $this->appLogger->crit($e);
       $errorMessage = $e->getMessage();
       throw new \Exception ($errorMessage);
}

Expected results

The query should return the value it was passed as a parameter inside an associative array:
["ACCT_UNIT" => "113"]

Actual results

I received the following error:

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 2097152) (tried to allocate 140346646331424 bytes) in /tmp/vendor/zendframework/zend-db/src/Adapter/Driver/Pdo/Connection.php on line 425
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants