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

Link to comment
Share on other sites

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.

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.