【问题标题】:db2_fetch_object(): Fetch Failure thrown when query works in strsqldb2_fetch_object():当查询在 strsql 中工作时抛出 Fetch Failure
【发布时间】:2015-11-18 23:07:50
【问题描述】:

在 PHP 中运行查询时出现以下错误:

警告:db2_fetch_object(): Fetch Failure in ... 第 15 行

奇怪的是,当我在 I5 终端中使用 strsql 运行相同的查询时,它可以工作,并且我得到了一个不错的记录集。我运行的查询是SELECT * FROM TABLE(U8.feedconst(0)) AS t1

U8.feedconst(0) 是一个表函数,驻留在 U8 库中,但从用户的库中提取数据。当我使用 IBM 终端时,我将用户的库设置为 uasetlibl。该库在 $this->user->library 中的 PHP DB2 连接中指定(该库已成功用于其他查询)。

这是 PHP 代码:

$this->conn = db2_connect(
        \HOST, 
        $this->user->username, 
        $this->user->password,
        array('i5_libl' => $this->user->library . ' ' . \PROD_LIB,
            'i5_naming' => DB2_I5_NAMING_ON)
);
$sql = 'SELECT * FROM TABLE(U8.feedconst(0)) AS t1';
$stmt = db2_prepare($this->conn, $sql);
if ($stmt) {
    $this->user->log('stmt = ' . strval($stmt), true);
    $exec = db2_execute($stmt);
    if ($exec) {
        $this->user->log('exec = ' . strval($exec), true);
        $this->user->log('db2_stmt_errormsg = ' . db2_stmt_errormsg($stmt), true);
        while ($row = db2_fetch_object($stmt)) {
            $this->user->log($sql, true);
        }
    }
}

日志显示在db2_fetch_object() 行之前一切正常:

2015-11-18 10:43:53pm : stmt = Resource id #21
2015-11-18 10:43:53pm : exec = 1
2015-11-18 10:54:27pm : db2_stmt_errormsg = 

如您所见,我尝试使用 db2_stmt_errormsg() 从 DB2 获取真正的错误,但它没有返回任何内容。

我查看了其他类似的问题,例如 Warning: db2_fetch_assoc(): Fetch FailureDB2 fetch failure error,但它们似乎无法解决我的情况。

【问题讨论】:

    标签: php db2 db2-400


    【解决方案1】:

    我找到了悲伤的原因。似乎 table 函数内部使用了一个额外的库。由于该表函数在不同的库中具有依赖关系,并且该其他库未包含在我的库列表中,因此返回给 PHP 的记录集是空的。

    它在 i5 终端中工作,因为我的终端会话已经设置为在其库列表中包含其他库,而我不知道。

    当我在连接中将其他内部库添加到我的库列表时,查询在 PHP 中运行良好。

    如果其他人遇到这种情况,请确保包含查询使用的所有库,包括任何可能是内部依赖项的库。

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 1970-01-01
      • 2018-03-11
      • 2019-11-21
      • 2022-09-22
      • 2015-12-15
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      相关资源
      最近更新 更多