note 35896 added to function.mysql-error
| From: | php at project2501 dot plus dot com | Date: | Thu, 18 Sep 2003 14:57:01 +0000 |
| Subject: | note 35896 added to function.mysql-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56702@lists.php.net to get a copy of this message | ||
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";
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-error.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35896
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35896&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35896&report=yes