Jump to content

Archived

This topic is now archived and is closed to further replies.

hadoob024

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

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!

Share this post


Link to post
Share on other sites

×

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.