php数据库批量修改工具,WordPress批量修改数据库表前缀php工具代码

为什么要修改wordpress数据库表前缀:一是为了安全,不定期修改wordpress数据库表前缀是安全的专业建议之一。二是换空间了,原来数据库已存在同一前缀的表。

现在只需要上传一个php工具,不用进数据库就能批量修改wordpress数据库表前缀了。先看 php工具代码:

在进行下列操作之前,请务必备份数据库,否则后果自负。

/**

* 修改wordpress表名前缀的工具.

*filename:reset_suffix.php

* @By 偶米工作室

*/

header(“Content-type: text/html; charset=utf-8”);

/下面两行您需要修改///

$oldtablepre=wentong_’; //旧的表前缀

$newtablepre=’wentong_org_’; //您要修改成新的表前缀

/上面两行您需要修改///

##########@以下请勿修改@###########################!DONT CHANGE BELOW!##################################################

require_once( dirname(__FILE__) . ‘/wp-load.php’ );

$tables=array(“{$oldtablepre}commentmeta”,”{$oldtablepre}comments”,”{$oldtablepre}links”,”{$oldtablepre}options”,”{$oldtablepre}postmeta”,”{$oldtablepre}posts”,”{$oldtablepre}terms”,”{$oldtablepre}term_relationships”,”{$oldtablepre}term_taxonomy”,”{$oldtablepre}usermeta”,”{$oldtablepre}users”);

echo ‘

下面更改表名:
& lt;/hr>’;

foreach ($tables as $key => $value){

$oldtable=$value;

$newtable=str_replace($oldtablepre,$newtablepre,$value);

$wpdb->query(“ALTER TABLE `$oldtable` RENAME TO `$newtable`”);

echo ‘成功更改表名’.$oldtable.’为:’.$newtable.'
’;

}

echo ‘下面更改’.$newtablepre.’options表中的键值:


’;

$wpdb->query(“update `{$newtablepre}options` set `option_name`=replace(option_name,'{$oldtablepre}user_roles’,'{$newtablepre}user_roles’)”);

echo ‘成功更改’.$oldtablepre.’user_roles为:’.$newtablepre.’user_roles
’;

$meta_key=array(“{$oldtablepre}capabilities”,”{$oldtablepre}user_level”,”{$oldtablepre}autosave_draft_ids”,”{$oldtablepre}usersettings”,”{$oldtablepre}usersettingstime”);

echo ‘下面更改’.$newtablepre.’usermeta表中的键值:


’;

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.’为:’.$newoption.'
’;

}

echo ‘

’;

?>

新建一个reset_suffix.php,复制粘贴以上代码,格式转为 utf-8无bom编码,保存上传至 wp-config.php 同一文件夹。

在浏览器输入 http://wentong.org/reset_suffix.php(wentong.org换成你的域名)。

修改wp-config.php的表前缀为你新的表前缀。如本例子中的 wentong_org_

标签:wordpress专栏, wordpress主题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值