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

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)