Bead
Bead

Reputation: 363

PHP IBM SQL DB2 statement only updating only partially with no error messages

Code:

    $sql =      'UPDATE library/tablename ' .
           'SET foo1 = \'THIS IS A TEST\', foo2 = 1234567890, foo3 = 1234'.
           'WHERE foo4 = 165436';

    $stmt = db2_prepare($dbConn, $sql)
        or die("Error: Unable to prepare statement");

    $exec = db2_execute($stmt);

I run this in PHP and after it executes I go to look at the table and I see that the foo1 field has changed, but foo2 and foo3 remain their default values, which is zero.

If I run the $sql statement from "strsql" on the IBM terminal it runs and all fields are updated to the values I have specified. Does anyone have any idea as to what is going on here? This has had me stumped for hours.

Upvotes: 0

Views: 411

Answers (1)

bhamby
bhamby

Reputation: 15450

After running the execute, you probably want to check the value of SQLSTATE. That will show you the actual error that DB2 is throwing at you.

You can retrieve the SQLSTATE in PHP using db2_stmt_error(), which will give you the SQL state of the last execution (if you pass a particular resource, the last execution on that resource).

If you'd like to output a human-readable SQL Error Message, you can use db2_stmt_errormsg(), which will output the SQLSTATE and the corresponding error message string.

Upvotes: 1

Related Questions