In-Portal has kDBConnection class, that can handle any type of database interactions. When database query being executed produces an error, then it's handled differently based on criteria listed below:
debug mode enabled AND DBG_SQL_FAILURE option set in debug.php file - will be PHP fatal error and script stops
debug mode enabled AND DBG_SQL_FAILURE option not set in debug.php file - will be PHP warning and script continues to execute
debug mode is disabled - will be PHP warning and script continues to execute
All works ok, until you need to check if last database query ended with error in last 2 cases from above mentioned.
Class kDBConnection has "getErrorCode", "getErrorMsg" and "hasError" methods, that do the trick, but if there was a query with error before checked query, then error isn't cleared an all methods will tell, that there is an error, but there are none.
I propose to reset "last remembered error information" before running new database query.