Попробуйте что-то вроде этого:
<?php
function logToFile($filename, $msg)
{
$fd = fopen($filename, "a");
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
fwrite($fd, $str . "\n");
fclose($fd);
}
function logToMail($msg, $address)
{
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
mail($address, "Log message", $str);
}
function logToDB($msg, $type)
{
// open connection to database
$connection = mysql_connect("localhost", "joe", "pass") or die ("Unable to connect!");
mysql_select_db("logdb") or die ("Unable to select database!");
// formulate and execute query
$query = "INSERT INTO log (date, type, msg) VALUES(NOW(), '$type', '$msg')";
mysql_query($query) or die ("Error in query: $query. " .mysql_error());
// close connection
mysql_close($connection);
}
?>