Ejemplo n.º 1
0
 public function __construct($dsn, $user = "", $passwd = "")
 {
     if (!defined('PDOERR')) {
         define('PDOERR', PDO::ERRMODE_EXCEPTION);
     }
     $options = array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDOERR);
     if (!defined('PDO_ASSCO')) {
         define('PDO_ASSCO', PDO::FETCH_ASSOC);
     }
     try {
         parent::__construct($dsn, $user, $passwd, $options);
     } catch (PDOException $e) {
         $error = 'Failed to connect to Database! ' . $e->getMessage();
         cx_email_error('The Database is DOWN!!!' . $error);
         if (defined('CX_LIVE') && CX_LIVE === false) {
             echo "The Database is down!!! {$error}";
             // Show error msg on dev
             exit;
         } else {
             cx_global_error_handler();
             // Show error page on live
             exit;
         }
     } catch (Exception $e) {
         $error = 'Failed to connect to Database! ' . $e->getMessage();
         cx_email_error('The Database is DOWN!!!' . $error);
         if (defined('CX_LIVE') && CX_LIVE === false) {
             echo "The Database is down!!! {$error}";
             // Show error msg on dev
             exit;
         } else {
             cx_global_error_handler();
             // Show error page on live
             exit;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Connect to Database
  * @method connnectDatabase
  * @return void
  */
 protected function connect_database($dsn, $user = '', $passwd = '')
 {
     require_once CX_BASE_DIR . 'classes' . DS . 'cx' . DS . 'database' . DS . 'db.php';
     $this->database = new cx_db($dsn, $user, $passwd);
     if (!is_object($this->database)) {
         cx_email_error('The Database is DOWN!!!');
         if (defined('CX_LIVE') && CX_LIVE === true) {
             cx_global_error_handler();
             exit;
         } else {
             echo "The Database is down";
             exit;
         }
     }
     if (is_object($this->database)) {
         $this->database->error_callback_set('cx_global_error_handler');
         $this->database->init_db();
     } else {
         throw new \Exception('Unable to connect to database!!');
     }
 }
Ejemplo n.º 3
0
function cx_custom_error_checker()
{
    $a_errors = error_get_last();
    if (is_array($a_errors)) {
        if (defined('CX_LIVE') && CX_LIVE === true) {
            $msg = "Error: {$a_errors['message']} File:{$a_errors['file']} Line:{$a_errors['line']}.";
            cx_email_error($msg);
            cx_global_error_handler();
        } else {
            echo '<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">';
            echo '<base href="' . CX_BASE_REF . '"/>';
            echo '<link rel="stylesheet" href="../cx/assets/bootstrap/css/bootstrap.min.css" type="text/css" media="all" />';
            echo "</head>\r\n<body>\r\n";
            echo '<div class="alert alert-danger">';
            echo "{$a_errors['message']}, in file: {$a_errors['file']}, on line #{$a_errors['line']}.";
            echo '</div>';
            echo "</body>\r\n</html>";
        }
    }
}