note 71067 added to function.mssql-get-last-message
| From: | php at cybertinus dot nl | Date: | Fri, 10 Nov 2006 13:26:05 +0000 |
| Subject: | note 71067 added to function.mssql-get-last-message | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119584@lists.php.net to get a copy of this message | ||
I faced the same problem as Klaus. mssql_get_last_message only returns the last line of an error. I
tried Klaus' script, but that didn't work for me, because I use Microsoft SQL Server 2005
and not 2000, so @@ERROR is depricated and stuff. Also, a lot of messages in the error staid at %l,
%s and %s. And an error
"Error %i, on line %i. Statement: %s" isn't that usefull :). So I becan searching the
internet for a possible solution. I found the website http://www.4guysfromrolla.com/webtech/041906-1.shtml.
With that article I was able to write the following function:
<?php
function query($query, $db_conn, $message,)
{
$sql = "BEGIN TRY\n";
$sql .= "\t".$query."\n";
$sql .= 'END TRY
BEGIN CATCH
SELECT \'Error: \' + ERROR_MESSAGE()
END CATCH';
$result = @mssql_query($sql, $db_conn);
$return = mssql_fetch_assoc($result);
if(isset($return['computed']))
{
echo $sMelding, '. MSSQL returned:
'.$aReturn['computed'].'.<br>Executed query: '.nl2br($sql);
return false;
}
else
{
return $result;
}
}
?>
If you use this function, then you have to make your scripts as follows:
<?php
//make a connection to an MSSQL Server and save that connection in $db_conn
if(query('SELECT * FROM table', $db_conn, 'The selection failed'))
{
// The query was succesfull completed
}
else
{
// There was some error, and the error is already displayed on your screen, so this else-part is
usually not nessary.
}
?>
I hope this wil help somebody.
Best regards,
Cybertinus
----
Server IP: 194.109.193.119
Probable Submitter: 86.86.160.207
----
Manual Page -- http://www.php.net/manual/en/function.mssql-get-last-message.php
Edit -- https://master.php.net/note/edit/71067
Del: integrated -- https://master.php.net/note/delete/71067/integrated
Del: useless -- https://master.php.net/note/delete/71067/useless
Del: bad code -- https://master.php.net/note/delete/71067/bad+code
Del: spam -- https://master.php.net/note/delete/71067/spam
Del: non-english -- https://master.php.net/note/delete/71067/non-english
Del: in docs -- https://master.php.net/note/delete/71067/in+docs
Del: other reasons-- https://master.php.net/note/delete/71067
Reject -- https://master.php.net/note/reject/71067
Search -- https://master.php.net/manage/user-notes.php