Jump to content

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


hadoob024

Recommended Posts

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.