通过pdo_ibm模块连接到db2手动配置的错误SQL10007N -5005

时间:2016-05-09 10:42:25

标签: php pdo db2

我使用pdo_ibm连接到远程db2数据库时遇到困难,我按照IBM上的说明配置pdo_ibm库和linux客户端但由于我的php没有手动配置但是通过apt-get安装我不知道当前是不是错误可能是由于配置错误或其他原因造成的。

我的舞台是:     Linux debian wheezy     ibm db2客户端10.5     php 5.4.45     pdo_ibm 1.4

当我尝试使用以下代码连接db2时:

<?php
$usernameMaximo = '@user';
$passwordMaximo = '@password';
$connectionStringMaximo = 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=@databaseName;HOSTNAME=@xx.xxx.xxx.xx;PORT=50002;PROTOCOL=TCPIP;';
try {
  $connection = new PDO($connectionStringMaximo, $usernameMaximo, $passwordMaximo, array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
  );
  echo "Success";
}
catch (Exception $e) {
    var_dump($e);
}

我收到以下错误

object(PDOException)[2]
  protected 'message' => string 'SQLSTATE=     , SQLDriverConnect: -5005 [IBM][CLI Driver] SQL10007N Message "0" could not be retrieved.  Reason code: "3".
' (length=123)
  private 'string' (Exception) => string '' (length=0)
  protected 'code' => int 0
  protected 'file' => string '/apps/html/tests/pdo_db2.php' (length=28)
  protected 'line' => int 8
  private 'trace' (Exception) => 
    array (size=1)
      0 => 
        array (size=6)
          'file' => string '/apps/html/tests/pdo_db2.php' (length=28)
          'line' => int 8
          'function' => string '__construct' (length=11)
          'class' => string 'PDO' (length=3)
          'type' => string '->' (length=2)
          'args' => 
            array (size=4)
              ...
  private 'previous' (Exception) => null
  public 'errorInfo' => null

网络/防火墙已经检查,所以我可以通过squirrel客户端连接,任何人都面临同样的问题?

2 个答案:

答案 0 :(得分:3)

您是否尝试过提供here

的替代方法

以下示例显示了用于连接到db2cli.ini中编目为DB2_MAXIMO的DB2数据库的PDO_IBM DSN:

$db = new PDO("ibm:DSN=DB2_MAXIMO", "", "");

[DB2_MAXIMO]
Database=SAMPLE
Protocol=TCPIP
Port=50002
Hostname=my-db2-machine
UID=my-OS-user
PWD=my-OS-password

答案 1 :(得分:3)

您可以尝试设置正确的NCIM实例名称吗?默认情况下:

 DB2INSTANCE=db2inst1

要知道db2inst1是否是DB2实例的正确名称,请执行:

sudo su db2inst1
db2level

响应可能是这样的:

DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL09074"
with level identifier "08050107".
Informational tokens are "DB2 v9.7.0.4", "s110330", "IP23243", and Fix Pack "4".
Product is installed at "/opt/ibm/db2/V9.7".