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 is supposed to return the last message from MS-SQL. i.e. If a query fails, then mssql_get_last_message should return the relevant error message as a string.
However, in my case, the return value was a blank string.
In the end, 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 config 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 a proper 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.';
Note that by default, the timeout is set to 60.
Reminder: This function was completely removed in PHP 7, along with the rest of the mssql_* functions. You might want to think about migrating your MS-SQL queries over to the PDO object.