ibmdb / php_ibm_db2

ibm_db PHP driver DLL repository for Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

ic1011 opened this issue · comments

Hello!

I'm trying to set up a connection with remote DB2 running on IBM i series. It appears to be extremely hard to get it working with windows-based client.

The PHP version is 7.4.6 but I've also tried with 7.3.17 without success.

Here are the different ways I've tried to connect and the errors they return:

db2_connect("DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=X.X.X.X;PORT=446;DATABASE=db_name;PROTOCOL=TCPIP;UID=user1;PWD=pass1;", "", "");

The db2_connect() returns false and both db2_conn_error() db2_conn_errormsg() return empty strings.

new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=X.X.X.X;PORT=446;DATABASE=db_name;PROTOCOL=TCPIP;UID=user1;PWD=pass1;");

PHP Fatal error: Uncaught PDOException: SQLSTATE=, SQLAllocHandle

new PDO("odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=X.X.X.X;PORT=446;DATABASE=db_name;PROTOCOL=TCPIP;UID=user1;PWD=pass1;");

PHP Fatal error: Uncaught PDOException: SQLSTATE[IM004] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

odbc_connect("DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=X.X.X.X;PORT=446;DATABASE=db_name;PROTOCOL=TCPIP;UID=user1;PWD=pass1;");

PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed, SQL state IM004 in SQLConnect

Here is what I've done/tried so far:

  1. Installed the IBM Data Server Runtime Client version 11.5 for WIN64.
  2. Installed the license with the db2licm command.
  3. Installed and configured the DB2 PHP modules from this repository.
  4. Created a simple PHP script in order to test the connection to the database.
  5. Ran the script with administrator privileges - same errors.
  6. Followed the instructions mentioned at IBM and created a DB2USERS group and added the user (used to run the script ) to it. But again - same errors.

Before I got to this stage I've received another error, it was something along the lines of: "Cannot convert codepage 0 to codepage 1251". That one I've fixed by activating the "Beta: Use Unicode UTF-8 for worldwide language support" windows option.

I would really appreciate any help. Thank you in advance!

In the windows environment, I only managed to connect using the driver in version 11.1.x, with odbc and php 7.4.x driver.

In version 11.5 there was an error, even installing the full client or just odbc.

Tested on windows10 x64 and windows server 2012

@robsonpiere, thank you for your input!

I've tried "IBM Data Server Driver For ODBC and CLI v11.1.4050.860 (special_39510/64-bit)" but got the same error.

I got it working using a different driver, provided by the "IBM i Access Client Solutions". Please find more info and instructions at Obtaining IBM i Access Client Solutions. But it only works with PDO or odbc_connect, the db2_connect still has the same issue as mentioned before.

@ic1011 Does the connection through db2cli tool is working fine ?

@vnkbabu, no, it returns "Failed to alloc env handle". Please see ibmdb/node-ibm_db#652

But the strangest thing is that db2_connect() returns false and both db2_conn_error() and db2_conn_errormsg() return empty strings. Any idea why?

@ic1011 Does "php -m" returns the ibm_db2 without any errors ?
If it returns i suspect problem with the underling DB2 CLI driver which PHP ibm_db2 driver is using.
To validate this, try to run the following the CLI script using the db2cli tool located inside the <clidriver/IBM DB2 Client?/bin

conn.t
opt echo on
opt callerror on
sqlalloenv 1
sqlallocconnect 1 1
sqldriverconnect 1 1 "" 255 255 SQL_DRIVER_NOPROMPT
killenv 1

run this script like db2cli < file1.t
If connection through CLI/ODBC is success we have problem with php driver, if fails we have problem with the DB2 client setup.

@ic1011 will close this issue as its inactive from long time, user is free to reopen if he needs further help.