function _DatabaseHandler::db_error

4.x _DatabaseHandler.php _DatabaseHandler::db_error($msg = "")
5.x _DatabaseHandler.php _DatabaseHandler::db_error(Exception $ex)

Draw out the error onto the screen.

2 calls to _DatabaseHandler::db_error()
_DatabaseHandler::db_query in classes/_DatabaseHandler.php
This function is used to perform a database query. It uses PDO execute, which will take automatically replace ? with variables you supply as the arguments to this function, or as an array to this function. Either will work. Do this by using ?, or…
_DatabaseHandler::z__db_query in classes/_DatabaseHandler.php
This function is used to perform a database query. It can take simple replacement patterns, by using ?. If you actually need to have a ? in the query, you can escape it with ??. For example: $result = $db->db_query("SELECT * FROM table WHERE…

File

classes/_DatabaseHandler.php, line 385

Class

_DatabaseHandler

Code

function db_error(Exception $ex) 
 {
  global $user;

  $arr = $ex->getTrace();

  $when_ts = time();
  $when_english = format_date($when_ts);

  $message = $ex->getMessage();

  // If the message involves a complaint about the sql_mode, point the user to a
  // help page about setting the sql_mode.
  if (stristr($message, "sql_mode=")) {
    $message .= "<br><br><b>" . t("It appears this error is being caused because of your server's sql_mode setting.") . "</b> ";
    $message .= t("To set your sql_mode for MySQL, please see the following help page: <a href='http://getflightpath.com/node/1161' target='_blank'>http://getflightpath.com/node/1161</a>");
  }


  $file = $arr [2]["file"];
  if (strlen($file) > 50) {
    $file = "..." . substr($file, strlen($file) - 50);
  }


  $file_and_line = "Line " . $arr [2]["line"] . ": " . $file;


  // If we are on production, email someone!
  if (@$GLOBALS ["fp_system_settings"]["notify_mysql_error_email_address"] != "") 
   {
    $server = $_SERVER ["SERVER_NAME"] . " - " . $GLOBALS ['fp_system_settings']['base_url'];
    $email_msg = t("A MYSQL error has occured in FlightPath.") . "  
      Server: $server
      
      Timestamp: $when_ts ($when_english)
      
      Error:
      $message
      Location:
      $file_and_line
      
      Backtrace:
      " . print_r($arr, true) . "
      ";
    fp_mail($GLOBALS ["fp_system_settings"]["notify_mysql_error_email_address"], "FlightPath MYSQL Error Reported on $server", $email_msg);
  }

  fpm(t("A MySQL error has occured:") . " $message<br><br>Location: $file_and_line<br><br>" . t("The backtrace:"));
  fpm($arr);

  if (@$GLOBALS ["fp_die_mysql_errors"] == TRUE) {
    print "\n<br>The script has stopped executing because of a MySQL error:
                    $message<br>
                    Location: $file_and_line<br>\n
             Please fix the error and try again.<br>\n";
    print "<br><br>Timestamp: $when_ts ($when_english)
              <br><br>Program backtrace:
              <pre>" . print_r($arr, true) . "</pre>";
    die;
  }

  // Also, check to see if the mysql_err is because of a lost connection, as in, the
  // server went down.  In that case, we should also terminate immediately, rather
  // than risk spamming an email recipient with error emails.
  if (stristr($message, "Lost connection to MySQL server")
   || stristr($message, "MySQL server has gone away")) {

    print "<h2 style='font-family: Arial, sans serif;'>Database Connection Error</h2>
              <br>
              <div style='font-size: 1.2em; font-family: Arial, sans serif; padding-left: 30px;
                          padding-right: 30px;'>
              Sorry, but it appears the database is currently unavailable.  This may
              simply be part of scheduled maintenance to the database server.  Please
              try again in a few minutes.  If the problem persists for longer
              than an hour, contact your technical support
              staff.
              
              </div>
              
              ";


    // DEV:  Comment out when not needed.
    print "<pre>" . print_r($arr, TRUE) . "</pre>";

    die;
  }



}