简体   繁体   English

PHP-odbc_connect()-SQL错误

[英]PHP - odbc_connect() - SQL error

I am trying to connect IBM-DB2 database using odbc_connect . 我正在尝试使用odbc_connect连接IBM-DB2数据库。 Below is the sample script to test the connection for IBM-DB2 Database 以下是用于测试IBM-DB2数据库连接的示例脚本

$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 Windows中执行时,抛出以下异常

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 警告:odbc_connect():SQL错误:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称且未指定默认驱动程序,SQL状态IM002

When executed in Linux it throws below exception Linux中执行时,抛出以下异常

Warning: odbc_connect(): SQL error: [unixODBC][IBM][CLI Driver] SQL30081N A communication error has been detected. 警告:odbc_connect():SQL错误:[unixODBC] [IBM] [CLI驱动程序] SQL30081N已检测到通信错误。 Communication protocol being used: "TCP/IP". 使用的通信协议:“ TCP / IP”。 Communication API being used: "SOCKETS". 使用的通信API:“ SOCKETS”。 Location where the error was detected: "127.0.0.1" 检测到错误的位置:“ 127.0.0.1”

  • How could I resolve above error and connect to IBM-DB2 database? 如何解决以上错误并连接到IBM-DB2数据库?

odbc_connect documentation odbc_connect 文档

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. 如果仅在连接字符串中使用DSN,则odbc.ini(或等效名称)需要指定其他详细信息(主机名/ ip地址,端口号,数据库名称)等。

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. 如果未在连接字符串中使用DSN,则该连接字符串必须包含Db2服务器的主机名/ IP地址,以及端口号和数据库名称以及所需的任何其他属性。

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. Linux上的症状很可能是由于简单的问题引起的,例如错误或不完整的连接字符串或DSN定义,或者Db2实例未启动,或者Db2实例未在指定IP地址上的指定端口号上侦听。

PHP works fine with Db2 on Windows/Unix etc. PHP在Windows / Unix等操作系统上与Db2配合良好。

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). 考虑对PHP使用pdo_ibm或ibm_db2扩展,以在PHP和Db2之间实现更好的集成(尽管这些与您的症状无关)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM