Upon further investigation, I have come up with the following solution, please let me know if you have a better one!
Running my program in the command prompt with the argument -d display_errors
gave the warning:
SQL error: [Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired, SQL state S1T00 in SQLExecute in myPHPfile.php on line 31
From here, I used the basic idea from this answer as well as this technique to create my own error handler and do something special when the query timed out as follows
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (strpos($errstr, "Query timeout expired") !== false && $errno = E_WARNING){
# If there is a warning with text containing "Query timeout expired"
# Do your handling here
}
# Execute PHP internal error handler as well
return false;
}
set_error_handler("myErrorHandler");
I searched the string for "Query timeout expired" because most likely there are other $errstr
messages, depending on the ODBC; you may have to fiddle with this to make it work for you. I returned false
in my custom error handler so the default handler would also run.