function christians_error_handler($errno, $error, $file, $line, $context){
    $full_debug = 1; #set to 0 for less output.
    echo "Error $errno: $error<BR>\n";
    echo "In: $file, line number $line<BR>\n";
    if ($full_debug){
        print_r($context);
    }
    exit;
}

set_error_handler('christians_error_handler');

$cn=mysql_connect("databasewhatever");
$query="bogus meant to trigger error query";
$rs=mysql_query($query) or trigger_error(mysql_errno(), mysql_error());

Or, the K.I.S.S. solution
$rs = mysql_query($query) or die(mysql_error() . "<BR>\n$query<BR>\n");

Does die() give you a line number? If not, just put it in there.

--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
----- Original Message -----
From: Christian Dechery <[EMAIL PROTECTED]>
Newsgroups: php.general
Sent: Thursday, February 15, 2001 6:30 PM
Subject: [PHP] the best so far


> this is the best I got so far, for treating any sql syntax errors as
normal
> ERROrs and halting the parsing to report it.
>
> like:
>
> <?php
> define(LN,__LINE__);
> $cn=mysql_connect("databasewhatever");
> $query="bogus meant to trigger error query";
> $rs=mysql_query($query) or qerr(LN,$query);
>
> function qerr($errline,$query="unspecified")
> {
> $msg="<font face=verdana size=2 color=ff0000><b>SQL Syntax Error:</b>
> '$query'</font><br>\n";
> $msg.="<font face=verdana size=2 color=ff0000>[".mysql_errno()."]"
> ".mysql_error()."at $errline</font>";
> die($msg);
> }
>
> ?>
>
> anyone has a 'less-code' idea?
> I wanted a smaller code on the calls to qerr(), I'd really like to call a
1
> parameter (just the query) function and print the error_msg and the line
of
> code (the trickiest)...
> is there anyway I can define something as a mask for a function or
> something? I don't know... just having crazy ideas...
> this is pretty good as it is.. I just wanted even better...
> ____________________________
> . Christian Dechery (lemming)
> . http://www.tanamesa.com.br
> . Gaita-L Owner / Web Developer
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to