protected function databaseError($msg, $errorLevel = E_USER_ERROR, $sql = null, $parameters = array())
    {
        // Prevent errors when error checking is set at zero level
        if (empty($errorLevel)) {
            return;
        }

        // Format query if given
        if (!empty($sql)) {
            $formatter = new SQLFormatter();
            $formattedSQL = $formatter->formatPlain($sql);
            $msg = "Couldn't run query:\n\n{$formattedSQL}\n\n{$msg}";
        }

        if ($errorLevel === E_USER_ERROR) {
            // Treating errors as exceptions better allows for responding to errors
            // in code, such as credential checking during installation
            throw new DatabaseException($msg, 0, null, $sql, $parameters);
        } else {
            user_error($msg, $errorLevel);
        }
    }