Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-13-2009, 02:41 PM SQL Error Handling
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Hey all,

I have been searching google and these forums for a good solution for handling mysql errors but I cant find a solid solution so here I am

Till now I have been using:
mysql_query()or die(mysql_error);

Which obviously isnt a great solution for the life environment.

What I wanted to do was replace "mysql_error" with either a function or with an include statement and then have the error emailed to me (no point of submitting it to a database if the database is down). So when I use a function or include statement it emails fine, but its still displaying the mysql error message and I dont know how to stop that.

I have read you can change the INI file to have it stop outputting error messages but I still want to be able to use mysql_error in the production environment.

Thanks all, any help would be really appreciated!
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-14-2009, 12:11 AM Re: SQL Error Handling
Junior Talker

Posts: 3
Trades: 0
Hi,

Its bad practice to use error_display set to ON on Production environment.The other solution is you can make use of Exception.

read following for more details:

http://in2.php.net/manual/en/functio...or-handler.php
http://in2.php.net/manual/en/functio...on-handler.php

Hope these link help you.

Regards
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
priti is offline
Reply With Quote
View Public Profile
 
Old 07-14-2009, 07:23 AM Re: SQL Error Handling
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Thanks so much! set_error_handler solved the problem of having the PHP errors displayed.

The problem I am having now is that it is calling the error function 17 times, but only providing error messages to the function on the first instance. So this means I am getting 17 emails alerting me to one error but only the first email actually has any of the variables included. This is ok I guess because I could just make an if statement and only recognize it if $errno!="" but that seems silly.

Ill show you what I have right now. Here is the file that is supposed to handle the error messages.
PHP Code:
<?php
$old_error_handler 
set_error_handler("ErrorHandler");
function 
ErrorHandler($errno$errstr$errfile$errline)
{
date_default_timezone_set('-O500');
$date=date('l jS \of F Y h:i:s A');;
$page=$_SERVER['PHP_SELF'];
$errno=mysql_errno();
mail("name@email.com","SQL ERROR:".$errno,"Error Number:".$errno."\n\n Error Message:".mysql_error()."\n\n Date (no daylight):".$date."\n\n Page:".$page); 
echo 
"submit<br />";
}
?>
Here is the test file that generates an error:
PHP Code:
<?php
include "error_submit.php";

mysql_query("INSERT INTO ecoprofs(invalid) VALUES ('$nothing')") or die();
?>
Any help would be great

Oh and I realize I am being redundant with my variables in the error email page, I just didnt change them after I made the changes you suggested.
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE

Last edited by Truly; 07-14-2009 at 07:26 AM..
Truly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to SQL Error Handling
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14319 seconds with 12 queries