Changeset 230


Ignore:
Timestamp:
Jan 17, 2007 10:10:38 PM (17 years ago)
Author:
quinn
Message:

Q - added better DB error correction and dying with _fail() method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/DB.inc.php

    r209 r230  
    141141            }
    142142
    143             // Die or continue without connection?
    144             if ($this->getParam('db_die_on_failure')) {
    145                 echo "\n\n<!-- Script execution stopped out of embarrassment. There was a database error. -->";
    146                 die;
    147             } else {
    148                 return false;
    149             }
     143            // Die if db_die_on_failure = true, or just continue without connection
     144            return $this->_fail();
    150145        }
    151146
     
    178173        return mysql_close($this->dbh);
    179174    }
     175   
     176    /*
     177    * Die only if db_die_on_failure is true. This will be set to false for some cases
     178    * when a database is not required for web app functionality.
     179    *
     180    * @access   public
     181    * @param    string  $msg Print $msg when dying.
     182    * @return   bool    false If we don't die.
     183    * @author   Quinn Comendant <quinn@strangecode.com>
     184    * @version  1.0
     185    * @since    15 Jan 2007 15:59:00
     186    */
     187    function _fail()
     188    {
     189        if ($this->getParam('db_die_on_failure')) {
     190            echo _("This page is temporarily unavailable. Please try again in a few minutes.");
     191            die;
     192        } else {
     193            return false;
     194        }
     195    }
    180196
    181197    /**
     
    254270        // Error checking.
    255271        if (!$qid || mysql_error($this->dbh)) {
     272            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    256273            if ($this->getParam('db_debug')) {
    257274                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    258             } else {
    259                 echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
    260             }
    261             $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    262             if ($this->getParam('db_die_on_failure')) {
    263                 echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
    264                 die;
    265             }
     275            }           
     276            // Die if db_die_on_failure = true, or just continue without connection
     277            return $this->_fail();
    266278        }
    267279
Note: See TracChangeset for help on using the changeset viewer.