Warning: db2_fetch_assoc(): Fetch Failure

假如想象 提交于 2019-12-25 06:57:41

问题


This is probably very simple (I'm a novice), but I haven't been able to find an answer.

I'm using Linux, DB2 and PHP. My simple DB2 query from PHP only returns rows with integer values, but fails with "Fetch Failure" for anything else (varchar ...).

The query works with db2cli for all values:

echo "select COLUMN from TEST.TABLE"" | ./db2cli execsql -dsn SCHEMA

But fails in PHP:

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" . 

"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$passwd;";
$conn = db2_pconnect($conn_string, '', '');
if ($conn) {
        $sql = 'select COLUMN from TEST.TABLE';
        $options = array('cursor' => DB2_SCROLLABLE, 'binmode' => DB2_BINARY);
        $stmt = db2_prepare($conn, $sql, $options);
        if ($stmt) {
                $result = db2_execute($stmt);
                if (!$result) {
                        echo "exec errormsg: " .db2_stmt_errormsg($stmt);
                }
                $total_rows = db2_num_rows($stmt);
                        print "<br>Total rows: $total_rows";
                for ($i = 0; $i < $total_rows; $i++) {
                        $row = db2_fetch_array($stmt);
                        print "<br>$row[0]";
                }
        } else {
                echo "exec erromsg: " . db2_stmt_erromsg($stmt);
        }
        db2_close($conn);
        } else {
                echo "failed #2 ".db2_conn_errormsg();
        }



}

It will display any rows with integer values, but empty strings for everything else with the error "Fetch Failure" in the log. I tried db2_fetch_array, db2_fetch_assoc and db2_fetch_both.

Note: I've added the superfluous stuff like db2_scrollable and db2_num_rows later on in attempts to solve the problem. Unsuccessfully.

EDIT: I can even FILTER by the values that won't display ( SELECT column WHERE column = 'value') and it'll return the correct number of rows.

来源:https://stackoverflow.com/questions/27483943/warning-db2-fetch-assoc-fetch-failure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!