Php – ODBC connection failed to DB2 instance with PHP 5.3.6-13ubuntu3.6

db2ibm-midrangeodbcPHP

I have installed DB2 Express-C V9.7, unixODBC php5-odbc and iSerie-5.4.0-1.6 Drivers for Linux but when i try to connect to the DB2 server php return me this message :

[unixODBC][IBM][iSeries Access ODBC Driver]Communication link failure. comm rc=10061  -
CWBCO1049 - The iSeries server application is not started, SQL state 08004 in SQLConnect

I noticed with tcpdump that php try to connect on port 8741 instead of 50000.

netstat -anp tell me DB2 listen port 50000

This is my configuration file

/etc/odbcinst.ini :

[DB2]
Description     = ODBC for DB2
Driver          = /opt/ibm/iSeriesAccess/lib/libcwbodbc.so
Setup           = /opt/ibm/iSeriesAccess/lib/libcwbodbcs.so
FileUsage               = 1
Threading               = 2
DontDLClose             = 1
UsageCount              = 1

/etc/odbc.ini

[local_db2]
Driver = DB2
System = localhost
User = db2inst1
Password = MySecretPassword
Port = 50000
Database = dbname
Option = 1 

And my PHP Script :

$dsn = "local_db2";
$user = "db2inst1";
$passwd = "MySecretPassword";
$conn = odbc_connect($dsn,$user,$passwd );

echo "votre id de connexion est : $conn";

if ($conn <= 0) { 
 echo "\nErreur\n"; 
} 
  else { echo "\nSuccès\n"; 
}

odbc_close($conn);

Now i can connect to DB2 server. I have changed port of db2inst1 in /etc/services but server don't respond me.

My error message is (after a while):
[unixODBC][IBM][System i Access ODBC Driver]Communication link failure. comm rc=8405 – CWBCO1047 – The IBM i server application disconnected the connection, SQL state 08S01 in SQLConnect

Conclusion :

The first problem was the drivers for iSeries that was not the proper drivers for my configuration so i have installed the DB2 ODBC CLI driver which include drivers for linux.

The second problem was the odbc configuration.

My working /etc/odbc.ini configuration :

[DBNAME]
Driver=DB2

My working /etc/odbcinst.ini configuration :

[ODBC]
Trace       = yes
Tracefile       = /tmp/odbc.log

[DB2]
Description     = DB2 Driver
Driver      = /opt/ibm/db2/V9.7/lib32/libdb2.so
FileUsage       = 1
DontDLClose     = 1

You can get more details about your odbc connection in /tmp/odbc.log.
I used too the isql program who test odbc connection.
This program was in unixodbc linux package.

Thanks for your informations

Nicolas.

Best Answer

It's likely the database host server has not been started. The database host server accepts TCP/IP connections to the database.

You can check if it is currently active with the command WRKACTJOB SBSD(QSERVER) JOB(QZDASRVSD).

The command to start it is: STRHOSTSVR SERVER(*DATABASE).

The default port is 8471.