note 35896 deleted from function.mysql-error by didou
| From: | didou@php.net | Date: | Thu, 18 Sep 2003 15:03:28 +0000 |
| Subject: | note 35896 deleted from function.mysql-error by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56703@lists.php.net to get a copy of this message | ||
Note Submitter: php@project2501.plus.com
----
in reply to previous comment;
it's better, IMHO, to use somehing more like
<?
$debug = true;
$result = @mysql_query($query);
if($debug && !$result)
{
echo "<b>A fatal MySQL error occured</b>\n<br />Query: " . $query .
"<br />\nError: (" . mysql_errno() . ") " . mysql_error();
}
else if(!$result)
{
echo "Sorry, this page is under maintainance, please check back tomorrow";
}
?>
this way, when you've done testing, you can simply change line 1 to read
$debug = false;
and make the site live, knowing that if there are any errors, users aren't presented with a
bucket load of (to them) meaningless error messages. Also, hackers trying to crash your pages
won't be able to find out anything about your table structure, or the queries you're
using.
slightly off topic:
in fact, I use a debug function;
functions.php:
<?
$debug_level = "loud";
function debug($message,$override=false)
{
global $debug_level;
if($debug_level=="loud" || $override==true)
{
echo "<br /><br /><b>DEBUG MESSAGE:</b>
[".$message."]<br /><br />";
}
else if($debug_level=="quiet")
{
echo "<!--<b>DEBUG MESSAGE:</b> [".$message."] -->";
}
}
?>
main.php:
<?
include("functions.php");
// (connect to db here)
$query = "SELECT * FROM tbl";
$result = @mysql_query($query);
if(!$result)
{
debug("<b>A fatal MySQL error occured</b>\n<br />Query: " . $query .
"<br />\nError: (" . mysql_errno() . ") " . mysql_error());
echo "<br />Sorry, this page is under maintainance, please check back tomorrow";
}
?>