Typecho Links友情链接启用错误修复

作者:欧阳 发布时间:2021年01月18日 阅读: 11,338 分类:日积月累

调整博客模板时候关闭了友情链接,当再次启用时候发现提示错误信息:数据表建立失败,友情链接插件启用失败。错误号:42S01
后面百度一下发现是友情链接模块未判断数据库存在所以才会出现错误。
修复方法:找到友情链接插件Plugin.php文件

$code = $e->getCode();
    if(('Mysql' == $type && 1050 == $code) ||
            ('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
        try {
            $script = 'SELECT `lid`, `name`, `url`, `sort`, `image`, `description`, `user`, `order` from `' . $prefix . 'links`';
            $installDb->query($script, Typecho_Db::READ);
            return '检测到友情链接数据表,友情链接插件启用成功';                    
        } catch (Typecho_Db_Exception $e) {
            $code = $e->getCode();
            if(('Mysql' == $type && 1054 == $code) ||
                    ('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
                return Links_Plugin::linksUpdate($installDb, $type, $prefix);
            }
            throw new Typecho_Plugin_Exception('数据表检测失败,友情链接插件启用失败。错误号:'.$code);
        }
    } else {
        throw new Typecho_Plugin_Exception('数据表建立失败,友情链接插件启用失败。错误号:'.$code);
    }

修改为:

    $code = $e->getCode();
        if(('Mysql' == $type && 1050 == $code) ||
                ('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
            try {
                $script = 'SELECT `lid`, `name`, `url`, `sort`, `image`, `description`, `user`, `order` from `' . $prefix . 'links`';
                $installDb->query($script, Typecho_Db::READ);
                return '检测到友情链接数据表,友情链接插件启用成功';                    
            } catch (Typecho_Db_Exception $e) {
                $code = $e->getCode();
                if(('Mysql' == $type && 1054 == $code) ||
                        ('SQLite' == $type && ('HY000' == $code || 1 == $code))) {
                    return Links_Plugin::linksUpdate($installDb, $type, $prefix);
                }
                throw new Typecho_Plugin_Exception('数据表检测失败,友情链接插件启用失败。错误号:'.$code);
            }
        } else if('Mysql' == $type && '42S01' == $code){
            /* 如果数据库存在 */
            $script = 'SELECT `lid`, `name`, `url`, `sort`, `image`, `description`, `user`, `order` from `' . $prefix . 'links`';
            $installDb->query($script, Typecho_Db::READ);
            return '检测到友情链接数据表,友情链接插件启用成功';
        } else {
            throw new Typecho_Plugin_Exception('数据表建立失败,友情链接插件启用失败。错误号:'.$code);
        }

如果您还有什么疑惑或建议,欢迎在下方评论区继续讨论。
如果您觉得本文还不错,欢迎分享/打赏本文。当然,如果你无视它,也不会影响你的阅读。再次表示欢迎和感谢!

标签: typecho

已有 5 条评论 »

  1. 感谢大佬,成功解决了!

  2. 感谢!修复成功了!

  3. 非常有用,非常感谢!

    1. 很高兴能帮助到你。

添加新评论 »