网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > Blog(博客)/Wiki(维客)/RSS/Cms
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Blog(博客)/Wiki(维客)/RSS/Cms Blog(博客)/、Wiki(维客)、RSS、Cms等WEB 2.0相关技术讨论专区。

Reply
 
Thread Tools Display Modes
  #1   IP: 117.95.79.196
Old 2010-05-26, 09:21 PM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default 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>';
?>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:11 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.