MySQL Error Handling

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
computergenius
Forum Newbie
Posts: 7
Joined: Sat Feb 19, 2005 2:26 pm
Location: Spain

MySQL Error Handling

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post 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
computergenius
Forum Newbie
Posts: 7
Joined: Sat Feb 19, 2005 2:26 pm
Location: Spain

Looks like the logs, then...

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

http://php.net/ref.errorfunc may be of use for capturing the errors seperately. Output buffering may potentially help too.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
computergenius
Forum Newbie
Posts: 7
Joined: Sat Feb 19, 2005 2:26 pm
Location: Spain

I dare not...

Post 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.
computergenius
Forum Newbie
Posts: 7
Joined: Sat Feb 19, 2005 2:26 pm
Location: Spain

Does it catch the SQL errors?

Post by computergenius »

feyd wrote:http://php.net/ref.errorfunc may be of use for capturing the errors seperately. Output buffering may potentially help too.
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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you are thinking of auto_append.
Post Reply