diff --git a/f_config/config.php b/f_config/config.php index 82eda0ed..de27bb6f 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -7,6 +7,7 @@ mb_internal_encoding("UTF-8"); mb_http_output('UTF-8'); mb_regex_encoding('UTF-8'); + function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext){ if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting, so let it fall @@ -15,10 +16,33 @@ function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, in } $date = date("Ymd_His"); + $e = new \Exception(); - file_put_contents(ROOT.'/d_log/err_log.txt',"$date, $errno, $errstr, $errfile, $errline\n", FILE_APPEND); - - /* Don't execute PHP internal error handler */ - //return true; + $data = Json::encode([ + 'date'=>$date, + 'errno'=>$errno, + 'errstr'=>$errstr, + 'aux'=>'error', + 'trace'=>$e->getTraceAsString() + ], Json::PRETTY); + + file_put_contents(ROOT.'/d_log/err_log.txt',"$data\n", FILE_APPEND); } set_error_handler("\sammo\logErrorByCustomHandler"); + + +function logExceptionByCustomHandler(\Throwable $e){ + + $date = date("Ymd_His"); + + $data = Json::encode([ + 'date'=>$date, + 'errno'=>$e->getCode(), + 'errstr'=>$e->getMessage(), + 'aux'=>'exception', + 'trace'=>$e->getTraceAsString() + ], Json::PRETTY); + + file_put_contents(ROOT.'/d_log/err_log.txt',"$data\n", FILE_APPEND); +} +set_exception_handler('\\sammo\\logExceptionByCustomHandler'); \ No newline at end of file diff --git a/f_install/templates/RootDB.orig.php b/f_install/templates/RootDB.orig.php index 632dc48c..c59ce260 100644 --- a/f_install/templates/RootDB.orig.php +++ b/f_install/templates/RootDB.orig.php @@ -29,6 +29,8 @@ class RootDB if (self::$uDB === null) { self::$uDB = new \MeekroDB(self::$host, self::$user, self::$password, self::$dbName, self::$port, self::$encoding); self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true; + self::$uDB->throw_exception_on_error = true; + self::$uDB->throw_exception_on_nonsql_error = true; } return self::$uDB; } diff --git a/hwe/d_setting/DB.orig.php b/hwe/d_setting/DB.orig.php index 5ebb9046..71e7fdb3 100644 --- a/hwe/d_setting/DB.orig.php +++ b/hwe/d_setting/DB.orig.php @@ -27,6 +27,8 @@ class DB{ if(self::$uDB === null){ self::$uDB = new \MeekroDB(self::$host,self::$user,self::$password,self::$dbName,self::$port,self::$encoding); self::$uDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true; + self::$uDB->throw_exception_on_error = true; + self::$uDB->throw_exception_on_nonsql_error = true; } return self::$uDB; }