Jump to content


Photo

trigger_error() not passing error message string to custom error handler


  • Please log in to reply
No replies to this topic

#1 hadoob024

hadoob024
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 17 April 2006 - 05:25 AM

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:
//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);
}

And right now, this line:
$connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass);


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:
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);
}

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:
if (!$connresult)
{
    $problemtext = 'Error opening a db connection in searchlistingsprocess.php.\r\n'.mysql_error($connresult);
    trigger_error($problemtext, E_USER_ERROR);
}


Or if an error is generated by:
$connresult = mysql_connect('localhost', $searchdbuser, $searchdbpass);


Does my customer error handler get called automatically? And how can I get it to pass thru the message that I've defined? Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users