Announcement

Collapse
No announcement yet.

Is there a way to...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to...

    ... detect if the DB is up or down without the PHP Intrepreter printing an error?

    I decided to recode my site from scratch with a MySQL backend. However, I want parts of the site to be able to run off flat files when the DB is down. I know how to get it to run off flat files but I don't know how to detect if MySQL is running or not without PHP giving an error.

  • #2
    in htaccess you could put

    Code:
    php_flag display_errors off
    This should be used on any production website, it adds a touch more security (should an error crop up) with register_globals off.

    Or, you could use the @ operator before the connection command.

    PHP Code:
    @mysql_connect(blah); 
    Im not sure if the @ works for every command though.

    Maybe even error_reporting

    PHP Code:
    error_reporting(0); 

    Comment


    • #3
      yea could use

      if( !mysql_connect(db, username, password) ){
      // user flat files
      }

      Comment


      • #4
        Cool, thanks.

        Comment


        • #5
          Off the top of my head, you could do:

          mysql_connect(db, username, password) or die ("Your own error message");

          Comment


          • #6
            All of these suggestions should work fine, however the last 2 seem the best.

            Comment


            • #7
              My suggestions were not to see what was going on, just to supress the PHP warnings

              Comment


              • #8
                When the DB is offline, PHP gives a warning. I was trying to detect if the DB was offline so I didn't want PHP to give me a warning.

                Anyway, I got it to work by using @. Thankyou for your help.

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...
                X