0

Lately there have a couple of php errors on my clients website. Although they don't stop the website working they can stop certain parts working temporarily.

Is there anyway i can send an email when this occurs. For example earlier today the site got this error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`database`.`table`, CONSTRAINT `XXXX` FOREIGN KEY (`entity_id`) REFERENCES `xxxxxx` (`xxxx)' in... 

The only way of currently noticing this or other particular error is if someone brings it to our attention on the site but i want to be able to get an email if this occurs just by simply using

mail('[email protected]','subject',$err);

Is this possible?

2
  • 2
    If you use try/catch blocks where you catch errors you can send an e-mail in the catch. Commented Feb 4, 2015 at 18:27
  • 2
    Prepare to have your inbox destroyed Commented Feb 4, 2015 at 18:29

1 Answer 1

2
try{
    // your query
} catch($e){
    mail('[email protected]','error on query',$e->getMessage());

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.