Application_Error in global.asax not catching errors in WebAPI

Abstract out your error handling logic from Application_Error into its own function. Create a Web API exception filter. //register your filter with Web API pipeline //this belongs in the Application_Start event in Global Application Handler class (global.asax) //or some other location that runs on startup GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute()); //Create filter public class LogExceptionFilterAttribute : ExceptionFilterAttribute { … Read more

What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such

TL;DR Always have mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); in your mysqli connection code and always check the PHP errors. Always replace every PHP variable in the SQL query with a question mark, and execute the query using prepared statement. It will help to avoid syntax errors of all sorts. Explanation Sometimes your MySQLi code produces an error … Read more

How to avoid isset() and empty()

For those interested, I have expanded this topic into a small article, which provides the below information in a somewhat better structured form: The Definitive Guide To PHP’s isset And empty IMHO you should think about not just making the app “E_NOTICE compatible”, but restructuring the whole thing. Having hundreds of points in your code … Read more

How do I get PHP errors to display?

This always works for me: ini_set(‘display_errors’, ‘1’); ini_set(‘display_startup_errors’, ‘1’); error_reporting(E_ALL); However, this doesn’t make PHP to show parse errors – the only way to show those errors is to modify your php.ini with this line: display_errors = on (if you don’t have access to php.ini, then putting this line in .htaccess might work too): php_flag … Read more

How to deal with mysqli problems? mysqli_fetch_array(): Argument #1 must be of type mysqli_result

TL;DR Always have mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); in your mysqli connection code. It will let MySQL tell you what the actual problem is, be it with query, server, database or whatever. Always replace every PHP variable in the SQL query with a question mark, and execute the query using prepared statement. It will help to avoid … Read more