note 53572 rejected from function.mssql-get-last-message by didou
| From: | didou@php.net | Date: | Sun, 04 Feb 2007 13:43:53 +0000 |
| Subject: | note 53572 rejected from function.mssql-get-last-message by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122815@lists.php.net to get a copy of this message | ||
Note Submitter: klaus dot kuehne at gga-hannover dot de
----
MSSQL_GET_LAST_MESSAGE() has the major disadvantage, that only the last row of the SQLServer
message will be returned. And in most cases, this last row has no significant information or is even
empty.
In the meanwhile, I migrated my PHP-SQLServer application from MSSQL to ODBC, and now I use
ODBC_ERRORMSG() instead of MSSQL_GET_LAST_MESSAGE(). And this function works o.k.
I think that's a good idea to use ODBC instead of the native database interfaces. The
performance seems to be at the same level. And your application can easily ported to other database
systems.
The only minus of ODBC vs. MSSQL known to me is that ODBC cannot process return values of stored
procedures. No problem for most developers!
Regards,
Klaus
P.S.: Here is a small workaround for, the malfunctioning of MSSQL_GET_LAST_MESSAGE:
function get_sql_error ($con) {
$sql = "select @@ERROR as code";
$result = mssql_query($sql, $con);
$row = mssql_fetch_array($result);
$code = $row["code"]; // error code
$sql = "select cast (description as varchar(255)) as errtxt from
master.dbo.sysmessages where error = $code and msglangid = 1031"; // german
$result = mssql_query($sql, $con);
$row = mssql_fetch_array($result);
if ($row)
$text = $row["errtxt"]; // error text (with placeholders)
else
$text = "onknown error";
mssql_free_result($result);
return "[$code] $text";
}