Jump to content

Capture the full text of PHP Warning


superfriend

Recommended Posts

I'd like to capture the text of a PHP warning.

 

This is an internal process, no one will ever visit these php pages, so I want to send myself an email if the process fails.  Right now, as part of debugging this, I am forcing failures and echoing the content of my email to the page.  The first test is to use the wrong password. The following message is put on the page (broken into 3 sections for discussion purposes).

 

A) Warning: mysql_connect() [function.mysql-connect]:

B) Access denied for user 'xxx'@'localhost' (using password: YES)

C) in E:\php\www\folder\DatabaseConnectionInfo.php on line 8

 

mysql_error() gives me part B. 

Access denied for user 'xxx'@'localhost' (using password: YES)

 

How can I get parts A and C ?

Link to comment
https://forums.phpfreaks.com/topic/211187-capture-the-full-text-of-php-warning/
Share on other sites

Thanks, but not what I am looking for.  I had looked at that.  But you made me go back.  Poking around I found this:

 

http://us.php.net/manual/en/function.error-get-last.php

 

array error_get_last  ( void  )

 

 

 

Example #1 An error_get_last() example

<?php

echo $a;

print_r(error_get_last());

?>

 

The above example will output something similar to:

 

Array

(

    [type] => 8

    [message] => Undefined variable: a

    [file] => C:\WWW\index.php

    [line] => 2

)

 

Going to try to adapt this to what I need.

This is now working:

 

if (!(mysql_error() == ''))

{

$errorArray = error_get_last();

 

$emailBody = $emailBody."<br /> Section: ".$section."<br /> Error"

."<br />Type: ".$errorArray[type]

."<br />Message: ".$errorArray[message]

."<br />File: ".$errorArray[file]

."<br />Line: ".$errorArray[line]

;

 

//mail($emailAddress, $emailSubject.'-ERROR', $emailBody, $emailSender);

echo "<hr /><br /> $emailAddress $emailSubject.'-ERROR', $emailSender $section <br /><br /> $emailBody";

 

...

 

echoed to screen as part of $emailBody:

 

Section: Database Connect

Error

Type: 2

Message: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES)

File: E:\php\www\folder\DatabaseConnectionInfo.php

Line: 9

 

consider this done.

Archived

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

×
×
  • 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.