Connecting Tech Pros Worldwide Help | Site Map

Errors in php/mySQL

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 09:57 AM
knoak
Guest
 
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

  #2  
Old July 17th, 2005, 09:57 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: Errors in php/mySQL

knoak wrote:[color=blue]
> 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..[/color]

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!
  #3  
Old July 17th, 2005, 09:57 AM
jOrdi3.tar.gz@gmail.com
Guest
 
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.

  #4  
Old July 17th, 2005, 09:58 AM
jblanch
Guest
 
Posts: n/a
Default Re: Errors in php/mySQL


jOrdi3.tar.gz@gmail.com wrote:[color=blue]
> 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[/color]
accepts[color=blue]
> one argument and that is the error message to be displayed. If an[/color]
error[color=blue]
> is to occur then an email is sent to me and an error message is shown
> to the user.[/color]

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?";
}

  #5  
Old July 17th, 2005, 09:58 AM
jblanch
Guest
 
Posts: n/a
Default Re: Errors in php/mySQL

jOrdi3.tar.gz@gmail.com wrote:[color=blue]
> 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[/color]
accepts[color=blue]
> one argument and that is the error message to be displayed. If an[/color]
error[color=blue]
> is to occur then an email is sent to me and an error message is shown
> to the user.[/color]

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.

  #6  
Old July 17th, 2005, 09:58 AM
jblanch
Guest
 
Posts: n/a
Default Re: Errors in php/mySQL

jOrdi3.tar.gz@gmail.com wrote:[color=blue]
> 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[/color]
accepts[color=blue]
> one argument and that is the error message to be displayed. If an[/color]
error[color=blue]
> is to occur then an email is sent to me and an error message is shown
> to the user.[/color]

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.

  #7  
Old July 17th, 2005, 09:58 AM
jblanch
Guest
 
Posts: n/a
Default Re: Errors in php/mySQL


jOrdi3.tar.gz@gmail.com wrote:[color=blue]
> 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[/color]
accepts[color=blue]
> one argument and that is the error message to be displayed. If an[/color]
error[color=blue]
> is to occur then an email is sent to me and an error message is shown
> to the user.[/color]

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.

 

Bookmarks

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.