Page 1 of 1

mssql/error_reporting problems

Posted: Tue Apr 22, 2003 11:25 am
by shans
Hi *,

I am using php 4.2.0

'./configure' '--with-apache=../apache_1.3.22' '--enable-trans-sid' '--with-sybase=/usr/local/freetds' '--with-openssl=../openssl-0.9.6' '--with-mm=../mm-1.1.3' '--enable-track-vars'
on a linux 2.4.18-3

(freetds.0.61, track_errors and display_errors is on, register_globals as well)

There are 4 different cases to handle (coming from MS SQL Server 2000):

- dataset (select...)
- no valid resultset (insert, update....)
- system errors e.g. select cast('a string' as integer)
- raiserrors e.g. show_error
(create procedure show_error
as
raiserror ('My Errortext', 18, 1))

Playing around with "error_reporting-levels" did not solve the problem.

After a while I got a workaround for the first 3 cases:

Code: Select all

<?
.....
error_reporting (E_ALL);

ob_start();

$php_errormsg = ''; // to block: : Notice: Undefined variable:...

$conn = mssql_connect(......) or die ("$php_errormsg");

mssql_select_db(...) or die ("$php_errormsg");

$query_result = mssql_query($sql) or die ("$php_errormsg");

// here would come the cast error if not ob_start() were set

if(is_integer($query_result) and ($php_errormsg == null)) 
&#123; 
            ......the dataset output stuff
&#125;
elseif($php_errormsg != null)
&#123;
	ob_end_clean();
	ob_start();
	.....the system error message via $php_errormsg.....
&#125;
else 
&#123;
	
	..........the insert, update...output
&#125;

ob_end_flush();

?>
I've tried around a lot but the "raiserror stuff" stayed invisible at all.

I've looked for help from the freetds developers but they say that it is not a freetds problem resp. the errors where sent from freetds.

Now my 2 questions:

- is anybody having a better workaround for "my first 3 cases"?
resp. why does the error_reporting levels not act as expected?
- how do i get my "raiserror stuff" displayed?

Thx in advance for any idea...

Stefan

Posted: Wed Apr 23, 2003 12:35 pm
by chris22
Have you looked into custom error handlers?

I would also like to point out that an empty string ($php_errormsg) is not the same as null. If you're going to check for nullness, you have to set it to be null.

Otherwise, I can't figure out exactly what your problem is. What exactly is raiserror supposed to be/do?

solution

Posted: Thu Apr 24, 2003 6:11 am
by shans
http://lists.ibiblio.org/pipermail/free ... 06911.html
helps to solve the problem with the raiserror - it was a problem between sql server and freetds.

btw: raiserror throws an exception out of an sql procedure.

have fun stefan