Errors in php/mySQL

This is a discussion on Errors in php/mySQL within the PHP Language forums, part of the PHP Programming Forums category; Hi there, I wonder if there is any command to hide php and mySQL errors from the user, and replace ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-10-2004
knoak
 
Posts: n/a
Default Errors in php/mySQL

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
Reply With Quote
  #2 (permalink)  
Old 12-10-2004
Pedro Graca
 
Posts: n/a
Default Re: Errors in php/mySQL

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!
Reply With Quote
  #3 (permalink)  
Old 12-11-2004
jOrdi3.tar.gz@gmail.com
 
Posts: n/a
Default Re: Errors in php/mySQL

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.

Reply With Quote
  #4 (permalink)  
Old 12-12-2004
jblanch
 
Posts: n/a
Default Re: Errors in php/mySQL


jOrdi3.tar.gz@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?";
}

Reply With Quote
  #5 (permalink)  
Old 12-12-2004
jblanch
 
Posts: n/a
Default Re: Errors in php/mySQL

jOrdi3.tar.gz@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.

Reply With Quote
  #6 (permalink)  
Old 12-12-2004
jblanch
 
Posts: n/a
Default Re: Errors in php/mySQL

jOrdi3.tar.gz@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.

Reply With Quote
  #7 (permalink)  
Old 12-12-2004
jblanch
 
Posts: n/a
Default Re: Errors in php/mySQL


jOrdi3.tar.gz@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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:35 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0