當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DatabaseFactory::rollback方法代碼示例

本文整理匯總了PHP中DatabaseFactory::rollback方法的典型用法代碼示例。如果您正苦於以下問題:PHP DatabaseFactory::rollback方法的具體用法?PHP DatabaseFactory::rollback怎麽用?PHP DatabaseFactory::rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DatabaseFactory的用法示例。


在下文中一共展示了DatabaseFactory::rollback方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: exceptionHandler

/**
 * Exception handler
 * @param Exception $exception The exception raised
 */
function exceptionHandler($exception)
{
    try {
        $exceptionMessage = NULL;
        // If a transaction is in progress, rollback it
        if (DatabaseFactory::isTransactionInProgress()) {
            DatabaseFactory::rollback();
        }
        // logs exception before doing anything else, for logs to be filled even if an exception will occur during the exception treatment
        $logInstance = LogTool::getInstance();
        // debug exception in web context
        if ($exception instanceof GenericWarningException) {
            // logs warning
            $logInstance->logException($exception, LogTool::WARNING_LEVEL);
        } else {
            // logs error
            $logInstance->logException($exception);
        }
        $exceptionClass = get_class($exception);
        if ($exception instanceof GenericException) {
            // Displays message
            if (TranslationTool::isTranslationAllowed()) {
                $exceptionMessage = $exception->getUserLocalizedMessage();
            } else {
                $exceptionMessage = $exception->getMessage();
            }
        } else {
            // If error is not managed, displays generic message
            $exceptionMessage = 'GENERIC_EXCEPTION';
        }
        if (SystemTool::isAjaxContext()) {
            echo json_encode(array('error' => $exceptionMessage), true);
        } else {
            echo $exceptionMessage;
        }
    } catch (Exception $e) {
        echo $e->getMessage();
        try {
            LogTool::getInstance()->logException($e);
            echo $exceptionClass . ' raised : ' . $exceptionMessage;
            echo '+ ' . get_class($e) . ' while handling exception : ' . $e->getMessage();
            exit(LogTool::KO_RETURN_CODE);
        } catch (Exception $e2) {
            try {
                LogTool::getInstance()->logException($e2);
                echo $exceptionClass . ' raised (unable to display exception details)';
                exit(LogTool::KO_RETURN_CODE);
            } catch (Exception $e3) {
                echo 'unable to display exception details';
                exit;
            }
        }
    }
}
開發者ID:jonathan-vallet,項目名稱:craftanat,代碼行數:58,代碼來源:error_handler.inc.php


注:本文中的DatabaseFactory::rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。