ibm midrange - How can a handle errors from db2_fetch_assoc in PHP? -


I have a program that I'm running on my iSeries, sometimes that this query is sometimes sometimes Fills because there is no record to select. Every time the query fails, it logs php.log:

  PHP Warning: db2_fetch_assoc (): line 82 / code>  

I'm looking for a solution to prevent this error from logging. I know that I can already disable PHP error logging. I do not want to disable logging.

Here is a sample code:

  $ stmt = db2_prepare ($ conn, $ sql); If (! $ Stmt) {$ code = db2_stmt_error (); $ Msg = db2_stmt_errormsg (); // do not display TODO SQL in the output instead of logging it to die ("Failed to create $ sql. Reason: $ code $ msg"); } // (if (! $ Results)) $ bound1 = db2_bind_param ($ stmt, 1, "item", db 2_PARAM_IN); $ Bound2 = DB2_bind_param ($ STMT, 2, "House", DB 2_PARAM_IN); $ Bound 3 = DB2_bind_param ($ STMT, 3, "Counter", DB 2_PARAM_INOUT); If (! $ Bound 1 ||! $ Bound 2 ||! $ Bound 3) {Dies ("One or more parameters failed to bind."); } // // (if (! $ Bound1 || !! $ Bound 2 ||! $ Bound 3)) Perform with // bound parameter. $ Result = db2_execute ($ stmt); If (! $ Result) {$ code = db2_stmt_error (); $ Msg = db2_stmt_errormsg (); // do not display TODO SQL in the output instead of log it dead ("$ sql failed to execute cause cause $ code $ msg"); } // (if (! $ The result of)) if (! $ Counter) {return array (); //} // (if (! $ Counter)) / Return array to return to the successful caller $ rows = array (); While (($ line = db2_fetch_assoc ($ stmt)) = =) {$ rows] = $ line; } // (while ...) // it returns the caller to return $ rows; } // getParts  

Thanks!

If the DB2 driver logs that every time you try to get a result In which no more rows are available, you can avoid getting it back on the number of rows only:

  $ total_rows = db2_num_rows ($ stmt); {$ Row = db2_fetch_assoc ($ stmt) for ($ I = 0; $ i & lt; $ total_rows; $ i ++); ... do things ...}  

Comments