侧边栏壁纸
博主头像
欧阳博客

行动起来,活在当下

  • 累计撰写 143 篇文章
  • 累计创建 127 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

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

欧阳
2021-01-18 / 0 评论 / 0 点赞 / 10 阅读 / 0 字

调整博客模板时候关闭了友情链接,当再次启用时候发现提示错误信息:数据表建立失败,友情链接插件启用失败。错误号: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);
            }
0

评论区