1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need to set up a mysqli error page

Discussion in 'PHP' started by qwikad.com, Apr 8, 2016.

  1. #1
    I am using a software that doesn't have a config file or error page file of any sort. I want to have a custom error page in case there's no connection to the database. What are my options? Can I create is mysqli connet with a die in it in the index file and then add a custom error page to it? Will it work?
     
    qwikad.com, Apr 8, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Sure? Just do a redirect, or load something else than the standard index-file (via include or require) in case of an error.
     
    PoPSiCLe, Apr 8, 2016 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #3
    My problem is everything in that script is encoded via ionCube, so I do not know what is what there. I actually emailed the guys that sold me the script to see if they can assist me in that too. My question to you is is it possible that if I have my own mysqli connect with a custom error page that it can go to an error whereas the whole script will be still running fine. In other words, can mysqli connects to the same database give errors (fail to connect) independently? Or does a fail to connect happen to all of them at once?
     
    qwikad.com, Apr 9, 2016 IP
  4. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #4
    You should handle the error when you try a connection to the DB. You can handle it by exception. Catch if there is an error and send a message.

    
    try {
        connection
    } catch(Exception $e) {
        echo 'Message: ' .$e->getMessage();
    }
    
    Code (markup):
     
    Blizzardofozz, Apr 9, 2016 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    While intermittent errors _can_ happen, due to server errors, connection errors, server setup and dozens of other reasons. But no, usually, if you have a SQL-error it will be site-wide, not just one script, or part of a script. In that case it will most likely be a config error somewhere, in the failing script.
     
    PoPSiCLe, Apr 9, 2016 IP
  6. fisasti

    fisasti Active Member

    Messages:
    42
    Likes Received:
    5
    Best Answers:
    2
    Trophy Points:
    58
    #6
    If you can't change the source code because of ionCube, i think you could do the next thing. In the .htaccess redirect all the traffic to one new php file, in that new php file include the website index and previously check if you can connect to the database.
     
    fisasti, Apr 19, 2016 IP
  7. JeffH {wx}

    JeffH {wx} Greenhorn

    Messages:
    23
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    8
    #7
    I think your time would be far better vested in sorting out the issue that is causing your mysql server to become unavailable so often that you are seeking to create a custom error page for it.
     
    JeffH {wx}, Apr 21, 2016 IP
  8. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #8
    I never said it becomes unavailable often. I said "in case" it becomes unavailable. I like having custom error pages that look like the actual site. I'll probably do what @PoPSiCLe suggested. Will include an error page via an include. It's not a priority at the moment, just wanted to know what my options were.
     
    qwikad.com, Apr 21, 2016 IP
  9. JeffH {wx}

    JeffH {wx} Greenhorn

    Messages:
    23
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    8
    #9
    You can try setting a custom error handler like this :
    
    function error_handler($errno, $errstr, $errfile, $errline) {
       switch ($errno) {
         case E_NOTICE:
         case E_USER_NOTICE:
           $error = 'Notice';
           break;
         case E_WARNING:
         case E_USER_WARNING:
           $error = 'Warning';
           break;
         case E_ERROR:
         case E_USER_ERROR:
           $error = 'Fatal Error';
           break;
         default:
           $error = 'Unknown';
           break;
       }
       /*   Custom Action Here */
       return true;
    }
       
    // Error Handler
    set_error_handler('error_handler');
    
    Code (markup):
     
    JeffH {wx}, Apr 21, 2016 IP