function DatabaseHandler::db_error

6.x DatabaseHandler.php DatabaseHandler::db_error(Exception $ex)

Draw out the error onto the screen.

1 call 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…

File

classes/DatabaseHandler.php, line 246

Class

DatabaseHandler

Code

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

  $arr = $ex->getTrace();

  $when_ts = convert_time(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;

  @$query_and_args = print_r($arr [2]['args'], TRUE);

  // If we are on production, email someone!
  if (variable_get("notify_mysql_error_email_address", '') != "") 
   {
    $server = $_SERVER ["SERVER_NAME"] . " - " . $GLOBALS ['fp_system_settings']['base_url']; // intentionally use the GLOBALS here, since it comes from settings.php file.
    $email_msg = t("A MYSQL error has occured in FlightPath.") . "  
User: $user->name ($user->id)
Server: $server

Timestamp: $when_ts ($when_english)

*** Error: ***
$message

/-----------------------------------/

*** Location: ***
$file_and_line

/-----------------------------------/

*** Query/Args: ***
$query_and_args

/-----------------------------------/

*** Limited Backtrace: ***
" . print_r($arr, true) . "
";
    fp_mail(variable_get("notify_mysql_error_email_address", ''), "FlightPath MYSQL Error Reported on $server", $email_msg);
  }

  fpm(t("A MySQL error has occured:") . " $message<br><br>" . t("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;
  }



}