| topvip |
2010-05-26 09:21 PM |
wordpress中修改数据库的表前缀(php)
wordpress中修改数据库的表前缀,先备份好数据,再按以下方法操作:
1.以下代码保存为文件rename_suffix.php,注意要保存为utf-8编码格式!
2.修改$oldtablepre 和 $newtablepre 单引号中的值为你自己的
3.再把该文件上传到wp根目录(即与wp-config.php在同一个目录),
4.访问 http://你的wp博客地址/rename_suffix.php即可.
5.再修改wp-config.php中的$table_prefix 为新的值.
如:$table_prefix = ‘mywp_’;
Quote:
<?php
header("Content-type: text/html; charset=utf-8");
/**
* 修改wordpress表名前缀的工具.
*filename:rename_suffix.php
* *By 荒野无灯 http://blog.thinkstd.cn
*/
/////////下面两行您需要修改///////////
$oldtablepre='wp_'; //旧的表前缀
$newtablepre='mywp_'; //您要修改成新的表前缀
/////////上面两行您需要修改///////////
##########*以下请勿修改*###########################!DONT CHANGE BELOW!##################################################
require_once( dirname(__FILE__) . '/wp-load.php' );
$tables=array("{$oldtablepre}comments","{$oldtablepre}links","{$oldtablepre}options","{$oldtablepre}postmeta","{$oldtablepre}posts","{$oldtablepre}terms","{$oldtablepre}term_relationships","{$oldtablepre}term_taxonomy","{$oldtablepre}usermeta","{$oldtablepre}users");
echo '<div style="font-size:1.2em;"><span style="color:gray;font-weight:bold;">下面更改表名:</span><hr></hr>';
foreach ($tables as $key => $value)
{
$oldtable=$value;
$newtable=str_replace($oldtablepre,$newtablepre,$value);
$wpdb->query("ALTER TABLE `$oldtable` RENAME TO `$newtable`");
echo '成功更改表名'.$oldtable.'为:<span style="color:green;">'.$newtable.'</span><br></br>';
}
echo '<span style="color:gray;font-weight:bold;">下面更改'.$newtablepre.'options表中的键值:</span><hr></hr>';
$wpdb->query("update `{$newtablepre}options` set `option_name`=replace(option_name,'{$oldtablepre}user_roles','{$newtablepre}user_roles')");
echo '成功更改'.$oldtablepre.'user_roles为:<span style="color:green;">'.$newtablepre.'user_roles</span><br></br>';
$meta_key=array("{$oldtablepre}capabilities","{$oldtablepre}user_level","{$oldtablepre}autosave_draft_ids","{$oldtablepre}usersettings","{$oldtablepre}usersettingstime");
echo '<span style="color:gray;font-weight:bold;">下面更改'.$newtablepre.'usermeta表中的键值:</span><hr></hr>';
foreach ($meta_key as $key => $value)
{
$oldoption=$value;
$newoption=str_replace($oldtablepre,$newtablepre,$value);
$rs=$wpdb->query("update `{$newtablepre}usermeta` set `meta_key` =replace(meta_key,'$oldoption','$newoption')");
echo '成功更改'.$oldoption.'为:<span style="color:green;">'.$newoption.'</span><br></br>';
}
echo '</div>';
?>
|
|