odd_duck
odd_duck

Reputation: 4111

PHP - if error occurs, send email

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?

Upvotes: 0

Views: 1115

Answers (1)

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

}

Upvotes: 2

Related Questions