On Tue, April 10, 2007 1:08 pm, Paul Novitski wrote:
> mysql_query() returns true. This constitutes a hack because it
> depends entirely on the way the parser processes code rather than on
> explicit elements of the language.
The order of execution and boolean short-circuit is a Documented Feature.
This is no more a "hack" than relying on:
if ($foo || $bar){
}
to do the right thing.
That said, "or die..." is a shorthand for "you should replace this
with REAL error handling", so you're right, only for the wrong
reasons.
:-)
> define('bDebug', true);
> ...
> $bResult = mysql_query($sql);
> if (!$bResult) return ReportSQLError('checking user name',
> mysql_errno(), mysql_error(), $sql);
> ...
> function ReportSQLError($context, $errno, $errorMsg, $sql)
> {
> if (bDebug)
> {
> die("MYSQL ERROR $errno $context:<hr
> />\n$errorMsg<hr />\n$sql");
> }
> else
> {
> return $generate_friendly_error_message;
> }
> }
Personally, I wouldn't use this bDebug stuff...
It's too easy for a logic error in bDebug/non-bDebug to slip through
QA, and have the application working "differently" on the Production
server from the dev server.
This is particularly true if you don't have a test suite with 100% (or
close) code coverage.
Better to do something like:
$whatever = mysql_query($query, $connection);
if (!$whatever){
$messages[] = "Something went wrong. Nice user error message here.";
error_log(mysql_error($connection));
error_log($query);
}
$messages can be dumped out en masse in the presentation layer in a
suitable div.
Some would argue that things could go very wrong and fill up your log
files...
Well, yeah, if you're so inept and dis-organized as to not have a
process in place to detect and deal with a problem that it happens
enough to fill up your log files, then, yes, it could be a problem...
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php