Page 1 of 1
MySQL Error Handling
Posted: Sat Feb 19, 2005 2:31 pm
by computergenius
Is there a global method of error handling for MySQL? I am about to pull an active commercial site to bits, and need to be informed of any database errors that I cause in my steps towards perfection.
An error routine to email me would be perfect, logs would be adequate - but it must be something global, rather than requiring attention at page level.
Posted: Sat Feb 19, 2005 2:38 pm
by feyd
If for your own pages, you can do this through error handling functions (in php).. You should be using a database managment type class to interface with the database. This would allow you to send error information wherever you wish when one occurs.
http://dev.mysql.com/doc/mysql/en/log-files.html may be of interest.
Posted: Sat Feb 19, 2005 2:40 pm
by thegreatone2176
well i think maybe you could put an include that has an email script function in it and then do like
$res = mysql_query($link) or die(mysql_error()); and send the sql error as a parameter to the email function and have it mail the page and the error to u
pretty sure that wuold work
Looks like the logs, then...
Posted: Sun Feb 20, 2005 3:41 am
by computergenius
Both the replies are the kind of thing that I normally do - trap the errors when I create a page. However, I am about to attack a whole website, which I did not write, and cannot change every page - anyway, I may well miss some! At the moment, there is no real structure to the site or to the data.
Looks as though I am going to have to go for query log and binary log. Is this the correct direction? I have no idea what do to (as yet), and no idea what the logs will show me, so it would be helpful if anyone could tell me whether I am looking in the right place or not.
Posted: Sun Feb 20, 2005 8:59 am
by feyd
http://php.net/ref.errorfunc may be of use for capturing the errors seperately. Output buffering may potentially help too.
Posted: Sun Feb 20, 2005 9:14 am
by John Cartwright
thegreatone2176 wrote:well i think maybe you could put an include that has an email script function in it and then do like
$res = mysql_query($link) or die(mysql_error()); and send the sql error as a parameter to the email function and have it mail the page and the error to <span style='color:blue' title='ignorance is bliss'>you</span>
pretty sure that wuold work
Code: Select all
$res = mysql_query($link) or die(email_error(mysql_error()));
Email error being the function which emails you the error, and possibly add to a log file of some sort, or even database.
I dare not...
Posted: Sun Feb 20, 2005 10:06 am
by computergenius
Phenom wrote:Email error being the function which emails you the error, and possibly add to a log file of some sort, or even database.
But again, this requires hundreds of amendments to the code, which could in itself introduce errors. It's the correct way to go when you are starting to code, and something like it will be included in all the updates, but I dare not try this with existing unstable code on a busy commercial website.
I don't think that I can do what I want to do - keep an eye on the MySQL errors that I may introduce onto existing pages, as I try to normalize a cluttered database with code cluttered over dozens, perhaps hundreds of pages.
Does it catch the SQL errors?
Posted: Sun Feb 20, 2005 10:12 am
by computergenius
Does this help with failed SQL statements? I thought that this was just PHP errors. Although, I suppose, if the SQL statement is called via a PHP function, and the function fails because of the SQL statement...
I visualise a single file, reporting on the errors, and using (forget the name) the method used to add a bit of code to the end of all PHP pages.
Posted: Sun Feb 20, 2005 10:15 am
by feyd
you are thinking of auto_append.