0

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?
0

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

3 Comments

In this particular case, most likely the PORT and PROTOCOL. For example "DRIVER={IBM DB2};SERVER=10.100.200.99;DATABASE=TESTDB;PORT=50000;PROTOCOL=TCPIP;" might be a common default for non-SSL connections
Thanks for responding. Could you post a php-ibm_db2 snippet for connection which would give me clarity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.