By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Errors in php/mySQL

P: n/a
Hi there,

I wonder if there is any command to hide
php and mySQL errors from the user, and replace
them with a customized message, en maybe even
send a mail with the error to a defined email adress..

Greetings and thanks in advance
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
knoak wrote:
I wonder if there is any command to hide
php and mySQL errors from the user, and replace
them with a customized message, en maybe even
send a mail with the error to a defined email adress..


http://www.php.net/manual/en/ref.errorfunc.php

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2

P: n/a
You can do this several ways.

1. You can turn error reporting off by putting this at the top of the
script

error_reporting(0);

2. You can create an error handler like so

$connection = mysql_connect($host,$username,$password) or die("Could
not connect to MySqld. Can't continue!");

On scripts I create I add a function called report_error(); It accepts
one argument and that is the error message to be displayed. If an error
is to occur then an email is sent to me and an error message is shown
to the user.

Jul 17 '05 #3

P: n/a

jO***********@gmail.com wrote:
You can do this several ways.

1. You can turn error reporting off by putting this at the top of the
script

error_reporting(0);

2. You can create an error handler like so

$connection = mysql_connect($host,$username,$password) or die("Could
not connect to MySqld. Can't continue!");

On scripts I create I add a function called report_error(); It accepts one argument and that is the error message to be displayed. If an error is to occur then an email is sent to me and an error message is shown
to the user.


Well the easiest/best way to do this would acctually be to use the @
symbol before the function to cache the error, and then use the !
operator like so..
$query = @mysql_query("SELECT * FROM news",$db);
if(!$query){
//code for error here
echo "error?";
}

Jul 17 '05 #4

P: n/a
jO***********@gmail.com wrote:
You can do this several ways.

1. You can turn error reporting off by putting this at the top of the
script

error_reporting(0);

2. You can create an error handler like so

$connection = mysql_connect($host,$username,$password) or die("Could
not connect to MySqld. Can't continue!");

On scripts I create I add a function called report_error(); It accepts one argument and that is the error message to be displayed. If an error is to occur then an email is sent to me and an error message is shown
to the user.


Well the easiest/best way to do this would acctually be to use the @
symbol before the function to cache the error, and then use the !
operator like so..
$query = @mysql_query("SELECT * FROM news",$db);
if(!$query){
//code for error here
echo "error?";
}

I personally find this better because then you can have personalized
code like the emailing, because with the die function it just exits the
code with a message, if you use my method you can run any code you
want, or continue with the page. The @ is like saying "when an error
occurs, just return the error, don't display it".

examples..
@mysql_connect(...)
@mysql_select_db(...)
@mysql_query(...)

any function you want.

Jul 17 '05 #5

P: n/a
jO***********@gmail.com wrote:
You can do this several ways.

1. You can turn error reporting off by putting this at the top of the
script

error_reporting(0);

2. You can create an error handler like so

$connection = mysql_connect($host,$username,$password) or die("Could
not connect to MySqld. Can't continue!");

On scripts I create I add a function called report_error(); It accepts one argument and that is the error message to be displayed. If an error is to occur then an email is sent to me and an error message is shown
to the user.


Well the easiest/best way to do this would acctually be to use the @
symbol before the function to cache the error, and then use the !
operator like so..
$query = @mysql_query("SELECT * FROM news",$db);
if(!$query){
//code for error here
echo "error?";
}

I personally find this better because then you can have personalized
code like the emailing, because with the die function it just exits the
code with a message, if you use my method you can run any code you
want, or continue with the page. The @ is like saying "when an error
occurs, just return the error, don't display it".

examples..
@mysql_connect(...)
@mysql_select_db(...)
@mysql_query(...)

any function you want.

Jul 17 '05 #6

P: n/a

jO***********@gmail.com wrote:
You can do this several ways.

1. You can turn error reporting off by putting this at the top of the
script

error_reporting(0);

2. You can create an error handler like so

$connection = mysql_connect($host,$username,$password) or die("Could
not connect to MySqld. Can't continue!");

On scripts I create I add a function called report_error(); It accepts one argument and that is the error message to be displayed. If an error is to occur then an email is sent to me and an error message is shown
to the user.


Well the easiest/best way to do this would acctually be to use the @
symbol before the function to cache the error, and then use the !
operator like so..
$query = @mysql_query("SELECT * FROM news",$db);
if(!$query){
//code for error here
echo "error?";
}

I personally find this better because then you can have personalized
code like the emailing, because with the die function it just exits the
code with a message, if you use my method you can run any code you
want, or continue with the page. The @ is like saying "when an error
occurs, just return the error, don't display it".

examples..
@mysql_connect(...)
@mysql_select_db(...)
@mysql_query(...)

any function you want.

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.