The other day, I came across a frustrating issue with the PHP function mssql_get_last_message.
Although my SQL query was failing, mssql_get_last_message was returning a blank string.
As you already know, this function returns the last message from MS-SQL.
In other words, if a query fails, then mssql_get_last_message should return the relevant error message.
However, in my case, the return value was a blank string.
Eventually, I discovered that the SQL query in question was taking an extraordinarily long time to execute. In my php.ini file, the mssql.timeout configuration value was set to 60 seconds. This configuration value determines how long PHP should wait for an answer from MS-SQL before giving up.
This meant that my query, which was taking longer than 60 seconds to execute, simply died without returning an error message.
To find out what your mssql.timeout value is, you can use the following snippet:
$mssqlTimeout = ini_get('mssql.timeout'); echo 'mssql.timeout is set to ' . $mssqlTimeout . ' seconds.';
By default, this timeout is usually set to 60.
Please note that this function will be removed in PHP 7, along with the rest of the mssql_* functions. Therefore, you might want to think about migrating your MS-SQL queries over to the PDO object.