请注意,本文编写于 976 天前,最后修改于 972 天前,其中某些信息可能已经过时。
将代码保存为px.php文件,然后上传至网站根目录,在浏览器地址(你的域名/px.php)问一下即可,出现ok代表成功了
如果没成功先去输入数据库账号密码再访问
特别提醒
:请在PHP7以下版本的服务器上执行。本操作涉及数据库,请提前做好备份工作。另外,文章cid重新排列后,上传的附件所属文章可能不正确(反正我是正确的),需手动修改。
<?php
/**
* Typecho重新排列不连续的文章ID
* 网站:https://www.xmbk-1302692218.cos.ap-shanghai.myqcloud.com/
*/
$hostname_blog = "localhost";
$database_blog = "数据库名";
$username_blog = "数据库用户名";
$password_blog = "数据库密码";
$blog = mysql_pconnect($hostname_blog, $username_blog, $password_blog) or trigger_error(mysql_error(),E_USER_ERROR);
$no = 1;
function change_id($cid)
{
global $no;
// 修改post cid,并修改分类、标签、自定义字段、评论的对应关系
$sql = 'update typecho_contents set cid = ' . $no . ' where cid = ' . $cid;
mysql_query($sql);
$sql = 'update typecho_relationships set cid = ' . $no . ' where cid = ' . $cid;
mysql_query($sql);
$sql = 'update typecho_comments set cid = ' . $no . ' where cid = ' . $cid;
mysql_query($sql);
$no = $no + 1;
}
mysql_select_db($database_blog, $blog);
$query_postRecord = "SELECT cid FROM typecho_contents ORDER BY cid ASC";
$all_postRecord = mysql_query($query_postRecord);
$row_postRecord = mysql_fetch_assoc($all_postRecord);
do {
change_id( $row_postRecord['cid'] );
} while ($row_postRecord = mysql_fetch_assoc($all_postRecord));
// 重新设置post id自增起点
mysql_query('alter table typecho_contents AUTO_INCREMENT = ' . $no);
echo 'ok';
?>
版权属于:惜墨炳廓
本文链接:https://xmbk.xyz/index.php/archives/165.html
本文来源于网络。以上图文,贵在分享,版权归原作者及原出处所有,内容为作者观点,文章仅供参考,切勿过度曲解,最终解释权归惜墨炳廓所有,如涉及版权等问题,请及时与我们联系:xiangming@xmbk.xyz我们将在36小时内处理小明博客规则及用户协议最新查看地址:https://shimo.im/docs/vGHdwcDp8DHJ3DXv