0
votes

I am trying to connect IBM-DB2 database using odbc_connect. Below is the sample script to test the connection for IBM-DB2 Database

$conn = odbc_connect("DRIVER={IBM DB2};SERVER=10.100.200.99;DATABASE=TESTDB;","john","doe");
if (!($conn)) { 
  echo "<p>Connection to DB via ODBC failed: ";
  echo odbc_errormsg ($conn );
  echo "</p>\n";
}

When executed in Windows it throws below exception

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002

When executed in Linux it throws below exception

Warning: odbc_connect(): SQL error: [unixODBC][IBM][CLI Driver] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "127.0.0.1"

  • How could I resolve above error and connect to IBM-DB2 database?
1

1 Answers

1
votes

odbc_connect documentation

If you are using only a DSN in the connection string then the odbc.ini (or equivalent) needs to specify the other details (hostname/ip-address, port-number, database name) etc.

If you are not using a DSN in the connection string, then that connection-string must include the hostname/ip-address of the Db2-server, along with the port-number and database name and any other attributes you need.

Your symptom on Linux is most likely due to simple issues like incorrect or incomplete connection string or DSN definition, or Db2-instance not started, or Db2-instance not listening on specified port-number on specified IP-address.

PHP works fine with Db2 on Windows/Unix etc.

Consider using pdo_ibm or ibm_db2 extensions to PHP to have better integration between PHP and Db2 (although these are not related to your symptoms).