Jump to content


Photo

email notify when error querying database


  • Please log in to reply
4 replies to this topic

#1 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 12 April 2006 - 11:44 PM

i wish to catch any errors that may happen when a query is made to the mysql database.

i have it so that an error message pops up when it happens but can i have an email sent to me telling me this too, as the visitor may not let me know.

can this be done?

thanks in advance.

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 13 April 2006 - 02:10 AM

That's something you'll have to do on the PHP end.. write a function for it, then you can do something like this:

$result = mysql_query(....) or email_me(mysql_error());

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 April 2006 - 04:50 AM

That's right -- basically, as long as you can trap the call the generates the error, you can handle it however you see fit (and so you should). Silent errors -- or even worse, errors that the user sees and can do nothing about -- should never exist.

I always get annoyed when I see the typical "an error has ocurred.... please contact the webmaster". If they know an error occurs, the webmaster should be contacted automatically! That's how it works on every project I've ever written.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 13 April 2006 - 07:44 AM

Please can you provide information on how you would do this.

thank you



[!--quoteo(post=364279:date=Apr 13 2006, 05:50 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 13 2006, 05:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
That's right -- basically, as long as you can trap the call the generates the error, you can handle it however you see fit (and so you should). Silent errors -- or even worse, errors that the user sees and can do nothing about -- should never exist.

I always get annoyed when I see the typical "an error has ocurred.... please contact the webmaster". If they know an error occurs, the webmaster should be contacted automatically! That's how it works on every project I've ever written.
[/quote]


#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 April 2006 - 08:13 PM

Well, I'm not particularly familiar with PHP's error/exception handling, but at least for DB connections and queries, you can simply call your own custom error handler on any errors instead of calling die(). For other parsing-related errors, I assume that there's a way to catch the DIE signal, much like there is in Perl.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users