Example #1
0
 /** 
  * If database error display results and perhaps exit program
  * @param string $errorString Error string from program attempting the database connection
  * @param string $query query that cause the error
  * @param array $values array of values passed to the query
  *
  * return - false on no error
  */
 function error($errorString, $query = "", $values = "")
 {
     global $session;
     $errorSql = false;
     if (!$this->db) {
         // database object is broken
         $errorSql = true;
         $error = "\nDatabase error " . date('d/m/Y H:i:s');
         $error .= "\nPackege Error: " . $errorString . "\nQuery: " . $query . "\n";
         $this->errorDescription = $error;
     } elseif ($this->db->ErrorNo() != 0) {
         // normal error
         $errorSql = true;
         $error = "\nDatabase error " . date('d/m/Y H:i:s');
         $error .= sprintf("\nRoutine producing error: %s\n", $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
         $error .= "\nPackege Error: " . $errorString . "\nQuery: " . $query . "\n";
         $error .= sprintf("ADODB Error: [%d]: %s\n", $this->db->ErrorNo(), $this->db->ErrorMsg());
         if (is_array($values) and count($values)) {
             "\nSql replacement arguments";
             "'" . implode("', '", $values) . "'\n";
         }
         if (trim($_SERVER['QUERY_STRING']) != "") {
             $error .= sprintf("\nQuery string: %s\n", $_SERVER['QUERY_STRING']);
         }
         if ($this->cfg->errorDisplayBacktrace) {
             $error .= "Debug backtrace\n";
             $backtrace = debug_backtrace();
             foreach ($backtrace as $routine) {
                 if (!isset($routine['file'])) {
                     // probably call_user_func
                     $error .= "call_user_func\n";
                 } else {
                     $error .= "Line " . $routine['line'] . " of " . $routine['file'] . "\n";
                     if (isset($routine['function'])) {
                         $error .= " In function " . $routine['function'] . "\n";
                         if (isset($routine['args']) and is_Array($routine['args'])) {
                             $error .= "  Arguments ";
                             foreach ($routine['args'] as $arg => $argValue) {
                                 if (is_array($argValue) or is_object($argValue)) {
                                     $argValue = serialize($argValue);
                                 }
                                 $error .= $arg . " = '" . $argValue . "' ";
                             }
                             $error .= "\n";
                         }
                     }
                 }
             }
         }
         $error .= sprintf("Users remote IP address: %s\n", $_SERVER['REMOTE_ADDR']);
         if (is_object($session) and $session->loggedIn) {
             // put in user info if available
             $userAdmin = new UserAdmin($session, '');
             $error .= sprintf("Users name: %s\n", $userAdmin->getName($session->userId, false));
             $error .= sprintf("Users id: %s\n", $session->userId);
         }
         $this->errorDescription = $error;
     }
     if ($errorSql) {
         $this->error = true;
         if ($this->cfg->displaySqlFaults) {
             echo '<head></head><body><pre>';
             echo $this->errorDescription;
             echo '</pre></body>';
         } else {
             error_log($error, $this->cfg->message_type, $this->cfg->errorLog);
             foreach ($this->cfg->errorAdmins as $toAddress => $toName) {
                 ECRIAmailer("SSP SQL error handler", $this->cfg->noReplyEmail, $toName, $toAddress, "SSP SQL error on " . $this->cfg->siteName, $error);
             }
         }
         if ($this->abortOnError) {
             die("<p>Database error: Information has been emailed to admin</p>");
         }
     }
     return $this->error;
 }