hadoob024 Posted April 17, 2006 Share Posted April 17, 2006 How do you pass an error message to your custom error handler using trigger_error()? I read the docs and did some searches, and I thought it was pretty straightforward, but I can't seem to get it to work. I have the following code:[code]//opening connection to db$connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass);if (!$connresult){ $problemtext = 'Error opening a db connection in searchlistingsprocess.php.\r\n'.mysql_error($connresult); trigger_error($problemtext, E_USER_ERROR);}[/code]And right now, this line:[code]$connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass);[/code]generates the following error message:"mysql_connect(): Access denied for user: 'searchuser@localhost' (Using password: YES)"And not the error message that I've defined in $problemtext.I can see that my custom error handler is being called, but the error message that I've defined in $problemtext never gets passed thru to the custom error handler. Here's the code for my custom error handler:[code]function my_error_handler($error_type, $error_string, $errFile, $errLine){ $userip = $_SERVER['REMOTE_ADDR']; $userhostname = $_SERVER['REMOTE_HOST']; $subject = 'Unexpected OFRE.com Error: '.date("F j, Y, g:i a"); $body = "Error Message: $error_string\r\n"."Error Code: $error_type\r\n"."ErrFile: $errFile\r\n"."ErrLine: $errLine\r\n"."User IP Address: $userip\r\n"."User Host Name: $userhostname\r\n"."Variable Dump: $dumpresults\r\n"."========================================================\r\n"; mail("admin@oursite.com", $subject, $body);}[/code]I receive an email with the error. But the message that I pass along thru $problemtext never comes thru. Do I even need to include this part:[code]if (!$connresult){ $problemtext = 'Error opening a db connection in searchlistingsprocess.php.\r\n'.mysql_error($connresult); trigger_error($problemtext, E_USER_ERROR);}[/code]Or if an error is generated by:[code]$connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass);[/code]Does my customer error handler get called automatically? And how can I get it to pass thru the message that I've defined? Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.