note 12352 modified in function.mssql-get-last-message by felipe

From: Date: Wed, 23 Jul 2008 12:57:46 +0000
Subject: note 12352 modified in function.mssql-get-last-message by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142591@lists.php.net to get a copy of this message
MS SQL doesn't set errors as mysql does. $php_error is set as a string that doesn't help at all. The error comes in form of a Warning, which isn't pretty. So what you can do is capture the output of the warning and create your own error message, something like this: function treat_mssql_error($buffer) { $buffer=ereg_replace("<br>\n<b>Warning</b>: MS SQL message:","<b>Error in query (SQL Server)</b>: ",$buffer); $buffer=explode("(severity",$buffer); return $buffer[0]."</font>"; } function my_query($query,$cnx) { global $sql_error; ob_start(); $result=mssql_query($query,$cnx); if(!$result) { $sql_error=treat_mssql_error(ob_get_contents()); ob_end_clean(); return false; } ob_end_clean(); return true; } you can set treat_mssql_error() to fit your needs, and there u go. A personal error handler. --was-- MS SQL doesn't set errors as mysql does. $php_error is set as a string that doesn't help at all. The error comes in form of a Warning, which isn't pretty. So what you can do is capture the output of the warning and create your own error message, something like this: function treat_mssql_error($buffer) { $buffer=ereg_replace("<br>\n<b>Warning</b>: MS SQL message:","<b>Error in query (SQL Server)</b>: ",$buffer); $buffer=explode("(severity",$buffer); return $buffer[0]."</font>"; } function my_query($query,$cnx) { global $sql_error; ob_start(); $result=mssql_query($query,$cnx); if(!$result) { $sql_error=treat_mssql_error(ob_get_contents()); ob_end_clean(); return false; } ob_end_clean(); return true; } you can set treat_mssql_error() to fit your needs, and there u go. A personal error handler. http://php.net/manual/en/function.mssql-get-last-message.php

« previous php.notes (#142591) next »