If your application is going to fail, you may as well have it do so in a spectacular fashion. Sure, you could just display a simple error message and be done with it, but that's no fun; it's much better to just ruin the system for everyone else. At least, that's how the users of Niall's newly inherited system believed it was designed. The previous maintenance developer just got accustomed to rebooting the server several times whenever the application froze and told the users there was nothing he could do, because there was nothing in the logs to say why it failed. Niall, instead, decided to take a peek at the code ...

function executeQuery($string)
  $result = mysql_query($sqlText) or die(
    "Query failed " . writeErrorToLog(
      "Query Failed: " .$sqlText . " " . mysql_error()
  return  $result;

function writeErrorToLog($owner,$description,$script)
  $script = str_replace($_SERVER['DOCUMENT_ROOT'], "", $script);
  $sqlText = 
    "INSERT INTO errorLog (ownerID,time,description,script) " .
    "VALUES ('" . $owner . ",Now(),'" . $description . "','" . $script . "')";
  executeQuery($sqlText, $_SERVER['PHP_SELF']);

  return "";
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!