superfriend Posted August 19, 2010 Share Posted August 19, 2010 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 ? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 19, 2010 Share Posted August 19, 2010 You can get all of the errors and use the error data however you wish: http://us.php.net/manual/en/function.set-error-handler.php Quote Link to comment Share on other sites More sharing options...
superfriend Posted August 19, 2010 Author Share Posted August 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
superfriend Posted August 19, 2010 Author Share Posted August 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.