I got odbc.ini setup with DSN to local DB2 Community edition v11.5.7 database. It runs on port 25010. I've verified it can connect via telnet localhost 25010. PDO_ODBC extension is also installed and enabled.
The problem came when trying to connect through remote client via PDO_ODBC using PHP, it returns error below:
Fatal error: Uncaught PDOException: SQLSTATE[08004] SQLDriverConnect: 10061 [unixODBC][IBM][System i Access ODBC Driver]Communication link failure. comm rc=10061 - CWBCO1049 - The IBM i server application is not started, or the connection was blocked by a firewall
After ran tcpdump
, it seems that it ALWAYS tries to use port 8471.
My code
<?php
$conn = new PDO('odbc:DSN=SAMPLE;NAM=1;UID=db2inst1;PWD=password');
$sql = "select * from SAMPLE.EMPLOYEE";
$query = $conn->prepare($sql);
$query->execute();
$rows = $query->fetchAll();
print_r($rows);
Also tried isql client, the exactly same result.
isql localhost SAMPLE
PHP is 7.4 on ZendServer 2021. OS is Redhat Enterprise 7.9.
Below is odbc.ini
[SAMPLE]
Description = IBM i Access ODBC Driver
Driver = IBM i Access ODBC Driver
System = localhost
Port = 25010
ServiceName = db2c_db2inst1
#Trace=Yes
#TraceFile=/tmp/sql.log
UserID = DB2INST1
Password = password
Naming = 0
Database = SAMPLE
CommitMode = 1
Why is it always trying to connect to the wrong port 8471? How can I fix it?