Log MySQL - errors to syslog and do not print them in public, fixes #214

Signed-off-by: Florian Aders (EleRas) <eleras@froxlor.org>
This commit is contained in:
Florian Aders (EleRas)
2011-06-23 16:18:48 +02:00
parent f6af38a2c3
commit 9955bed2c1

View File

@@ -135,7 +135,7 @@ class db
} }
} }
/* /*
* this is not for 0.9.x * this is not for 0.9.x
*/ */
//mysql_query("SET NAMES utf8", $this->link_id); //mysql_query("SET NAMES utf8", $this->link_id);
//mysql_query("SET CHARACTER SET utf8", $this->link_id); //mysql_query("SET CHARACTER SET utf8", $this->link_id);
@@ -340,27 +340,25 @@ class db
{ {
global $filename; global $filename;
$text = 'MySQL - Error: ' . str_replace("\n", "\t", $errormsg);
if($mysqlActive) if($mysqlActive)
{ {
$this->geterrdescno(); $this->geterrdescno();
$errormsg.= "\n"; $text .= "; ErrNo: " . $this->errno . "; Desc: " . $this->errdesc;
$errormsg.= 'mysql error number: ' . $this->errno . "\n";
$errormsg.= 'mysql error desc: ' . $this->errdesc . "\n";
} }
$errormsg.= 'Time/date: ' . date('d/m/Y h:i A') . "\n";
if($filename != 'cronscript.php') if($filename != 'cronscript.php')
{ {
$errormsg.= 'Script: ' . htmlspecialchars(getenv('REQUEST_URI')) . "\n"; $text .= "; Script: " . getenv('REQUEST_URI') . "; Ref: " . getenv('HTTP_REFERER');
$errormsg.= 'Referer: ' . htmlspecialchars(getenv('HTTP_REFERER')) . "\n";
die(nl2br($errormsg));
} }
else else
{ {
$errormsg.= 'Script: -- Cronscript --' . "\n"; $text .= "; Script: cronscript";
die($errormsg);
} }
openlog("Froxlor", LOG_NDELAY, LOG_USER);
syslog(LOG_ERR, $text);
closelog();
die("A MySQL error occured, This should not happen, a detailed description may be found in Syslog");
} }
} }