better (cleaner and smaller) code

From: Date: Tue, 20 Feb 2001 01:16:42 +0000
Subject: better (cleaner and smaller) code
Groups: php.general 
Request: Send a blank email to php-general+get-40669@lists.php.net to get a copy of this message
To handle sql syntax errors (including, the query, the Line number of the code and possibly the file name) I came up with this... define(LN,__LINE__); $query="bogus query to cause error"; $rslt=mysql_query($query) or query_error(LN,$query); (*) this one works fine but I have to pass __LINE__ (LN) as an argument... and I don't like that... (*) function query_error($line,$query="unspecified) {
        $errstr="<font face=verdana size=2 color=ff0000><b>SQL Error</b>: '$query' failed at line $line<br>\n";
        $errstr.=mysql_errno()." : ".mysql_error()."</font>";
        die($errstr);
} or $rslt=mysql_query($query) or user_error(mysql_error()." at '$query'",E_USER_ERROR); works fine too, gives me the filename, the line and handles the error more PHP-likely... but still it's a huge function call to EVERY single query... I want to write at least code as possible and get the error, the query, the line number and (possibly) the filename.. isn't there anyway I could build a mask for a function or something like that to pass __LINE__ as an argument always.. I don't know... any ideas? ____________________________ . Christian Dechery (lemming) . http://www.tanamesa.com.br . Gaita-L Owner / Web Developer

« previous php.general (#40669) next »