【发布时间】: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 Failure 和 DB2 fetch failure error,但它们似乎无法解决我的情况。
【问题讨论】: