将代码保存为php文件,上传至网站根目录,(记得填入自己的数据库名和密码)在浏览器地址栏访问一下即可。
特别提醒:
请在PHP7以下版本的服务器上执行
。本操作涉及数据库,请提前做好备份工作。另外,文章cid重新排列后,上传的附件所属文章可能不正确,需手动修改。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <?php
$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; $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));
mysql_query('alter table typecho_contents AUTO_INCREMENT = ' . $no); echo 'ok'; ?>
|