doq1969 2018-04-17 07:19
浏览 444

PHP - odbc_connect() - SQL错误

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>
";
}

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条回答 默认 最新

  • duanji5569 2018-04-17 07:48
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog