/    Sign up×
Community /Pin to ProfileBookmark

Email MySQL Errors to you

Hi there

If i have this query for example,

[code=php]
$sql = “SELECT * FROM tblRegister WHERE UserID=’$DBUserID’ AND `TimeStamp`=’$DBDate’ ORDER BY `TimeStamp` DESC LIMIT 1”;
$qry = mysql_query($sql) or die(“Query failed ($sql) ” . mysql_error()); ;
[/code]

Is it possible for a script to email me the error and the query and from what PHP it was so that i can fix it ASAP? Is there any other ways of mailing any erros users may have to me so i can fix any problems ASAP? (Apart from automailing me the contents of a 404 or whatever)

Thanks!,
Scott

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@itbeingsJan 02.2007 — That should be easy I guess. Your query is assigned a variable as in $qry. You can declare the variable in a mail function if there is an error. List this but I've not tried it before....

if(isset(mysql_error())){

mail(); //mail function

}
Copy linkTweet thisAlerts:
@NightShift58Jan 02.2007 — [code=php]<?php
function dying_mail($errorMessage="") {

$thisDATETIME = date("Y-m-d H:i:s");
$thisSERVERIP = $_SERVER['SERVER_ADDR'];
$thisSERVERNA = $_SERVER['SERVER_NAME'];
$thisPROTOCOL = $_SERVER['SERVER_PROTOCOL'];
$thisMETHOD = $_SERVER['REQUEST_METHOD'];
$thisHOST = $_SERVER['HTTP_HOST'];
$thisREFERER = $_SERVER['HTTP_REFERER'];
$thisAGENT = $_SERVER['HTTP_USER_AGENT'];
$thisCLIENTIP = $_SERVER['REMOTE_ADDR'];
$thisPAGE = $_SERVER['REQUEST_URI'];
$thisCLIENTHOST = gethostbyaddr($thisCLIENTIP);
$thisSUBJECT = "Automated Error Report";

IF ($errorMessage == "") :
$errorMessage = "No error message provided by calling script.";
ENDIF;

$mailTo = "Webmaster <[email protected]>";
$mailFromAddr = "[email protected]";
$mailFrom = "From: Webmaster LoddonExplorer <[email protected]>rn";

$mailMessage = $thisSUBJECT . "n";
$mailMessage .= "------------------------------" . "n";
$mailMessage .= "Error Page : " . $thisPAGE . "n";
$mailMessage .= "------------------------------" . "n";
$mailMessage .= "Date/Time : " . $thisDATETIME . "n";
$mailMessage .= "Server IP : " . $thisSERVERIP . "n";
$mailMessage .= "Server Name: " . $thisSERVERNA . "n";
$mailMessage .= "Host : " . $thisHOST . "n";
$mailMessage .= "Protocol : " . $thisPROTOCOL . "n";
$mailMessage .= "Method : " . $thisMETHOD . "n";
$mailMessage .= "Referer : " . $thisREFERER . "n";
$mailMessage .= "------------------------------" . "n";
$mailMessage .= "Client IP : " . $thisCLIENTIP . "n";
$mailMessage .= "Client Host: " . $thisCLIENTHOST . "n";
$mailMessage .= "Browser : " . $thisAGENT . "n";
$mailMessage .= "------------------------------" . "n";
$mailMessage .= "Error Text : " . $errorMessage . "n";
$mailMessage .= "------------------------------" . "n";
@mail($mailTo, $mailSUBJECT, $mailMessage, $mailFrom);

die($errorMessage);
}
?>[/code]
You would change this:[code=php]$qry = mysql_query($sql) or die("Query failed ($sql) " . mysql_error());[/code]to:[code=php]$qry = mysql_query($sql) or dying_mail("Query failed ($sql) " . mysql_error());[/code]You're quite free in your choice of function name...
Copy linkTweet thisAlerts:
@scottyrobauthorJan 02.2007 — Ahh thats a nice simple text to understand and manipulate ?

THanks very much for that! ?
Copy linkTweet thisAlerts:
@NightShift58Jan 02.2007 — You're welcome...
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...