Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Advice on Error Handler ...

    We utilize several Includes which output
    results from a MySQL script.

    The Includes look like this:

    Code:
    <? include "http://www.site.com/php/psDynamic/psDynamic.php?command=view&cid=89" ; ?>
    This code is trouble-free until we encounter the occasional SQL error.
    If an error occurs, (obviously) a MySQL error displays and screws up the screen.

    What I'd like to do is add some error handling.

    Something like...
    • Try the Include
    • If result contains text 'failed' or '503', then do not display, then exit.
    • Display Include


    Is this possible?
    Thanks!

  • #2
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    I think you are looking for this. Just enter @ operator before the include function or you can use this for a custom error message like this
    PHP Code:
    <?
    $test 
    = @include "http://www.site.com/php/psDynamic/psDynamic.php?command=view&cid=89";
    if(
    $test){
    echo 
    $test;
    }else{
    echo 
    'sorry: the page cannot be retrive now , u may try later';
    }
    ?>
    Last edited by skmd; 12-27-2007 at 01:02 AM.

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Location
    Nebraska
    Posts
    113
    Thanks
    0
    Thanked 2 Times in 2 Posts
    You should do your error handling inside each include that accesses the database. Your application should handle errors in a unified way as an application.

    I assume that you are using the die() function in conjunction with mysql_error() if you are getting actual errors echoed out. Using die() is a decidedly user-unfriendly and non-HTML compliant way to handle errors. Echoing out direct mysql errors in production is insecure. If you are getting numerous failed quiries then there is something much more serious going on in your code. Syntax errors isn't the only reason that queries can fail, but it's the most common. Conditions that cause syntax errors need to be cleaned up first and foremost.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •