// mysql error class
class MySqlError{
//
// private members
//
private $Server;
private $User;
private $Date;
private $Script;
private $Referrer;
private $Environment;
//
// public members
//
public $Database;
public $Message;
public $CommandText;
public $Parameters;
//
// constructor
//
public function __construct() {
$this->Server = $_SERVER['SERVER_NAME'];
$this->User = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : '';
$this->Date = date('Y-m-d H:i:s');
$this->Script = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
$this->Referrer = $_SERVER['HTTP_REFERER'];
$this->Environment = $this->var_dump_ret($_REQUEST);
}
//
// private methods
//
// return var_dump as a string
private function var_dump_ret($mixed) {
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
//
// public methods
//
// log error message to file and send email
public function Log() {
$message = 'User: ' . $this->User . "\n"
. 'Date: ' . $this->Date . "\n"
. 'Script: ' . $this->Script . "\n"
. 'Referrer: ' . $this->Referrer . "\n\n"
. 'Message: ' . $this->Message . "\n\n"
. 'CommandText: ' . "\n" . $this->CommandText . "\n\n"
. 'Parameters: ' . "\n" . $this->var_dump_ret($this->Parameters) . "\n"
. 'Environment: ' . "\n" . $this->Environment;
// append message to log file if it exists
if($handle = fopen(SITE_DIR . 'logs/errors.txt','ab')){
fwrite($handle, $message);
fclose($handle);
}
// email message
$oMail = new cMail();
$oMail->from = 'you@domain.com';
$oMail->addTo('you@domain.com');
$oMail->subject = "Website Error";
$oMail->message = $message;
$oMail->send();
}
}
?>
Wednesday, August 22, 2007
php 5 mysqli wrapper - error handler
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment