通過下面這個(gè)方法,輕松搞定,代碼如下,有用到的頂起。
目前創(chuàng)新互聯(lián)公司已為超過千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、拜城網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
復(fù)制代碼代碼如下:
?php
$database = "databaseName"; //數(shù)據(jù)庫名稱
$user = "root"; //數(shù)據(jù)庫用戶名
$pwd = "pwd"; //數(shù)據(jù)庫密碼
$replace ='pre_'; //替換后的前綴
$seach = 'pre1_'; //要替換的前綴
$db=mysql_connect("localhost","$user","$pwd") or die("連接數(shù)據(jù)庫失?。?.mysql_error()); //連接數(shù)據(jù)庫
$tables = mysql_list_tables("$database");
while($name = mysql_fetch_array($tables)) {
$table = str_replace($seach,$replace,$name['0']);
mysql_query("rename table $name[0] to $table");
}
?
如果是添加前綴只需要變化一點(diǎn)點(diǎn)
復(fù)制代碼代碼如下:
$table = str_replace($seach,$replace,$name['0']);換成
$table = $replace.$name['0'];
填寫前綴是為了防止一個(gè)數(shù)據(jù)庫中有很多個(gè)表,防止出現(xiàn)表重復(fù)的情況,還有最好使用PHP5.6版本進(jìn)行安裝,根據(jù)你的圖片顯示,明顯是PHP版本也有問題。
這樣是不行的~~對(duì)于常量不能像使用變量那樣直接放在里面,不能被PHP解釋。需要老老實(shí)實(shí)的用【?!窟M(jìn)行連接字符串才成。$sql="select*from".DB_PRE."admin";
開始之前 修改數(shù)據(jù)是一件風(fēng)險(xiǎn)很高的工作,開始之前必然就是做好數(shù)據(jù)庫備份,也可以把博客設(shè)置為維護(hù)狀態(tài)。在wp-config.php 修改數(shù)據(jù)庫前綴 打開你的 wp-config.php 文件,把數(shù)據(jù)庫前綴 wp_ 改成你想要的前綴,比如 wpjam_。 $table_prefix ='wpjam_';修改數(shù)據(jù)表名字 打開PHPMySQL,找到你的數(shù)據(jù)庫,然后執(zhí)行以下 SQL,把所有數(shù)據(jù)庫表前綴從 wp_ 改成 wpjam_。 RENAME table `wp_commentmeta` TO `wpjam_commentmeta`; RENAME table `wp_comments` TO `wpjam_comments`; RENAME table `wp_links` TO `wpjam_links`; RENAME table `wp_options` TO `wpjam_options`; RENAME table `wp_postmeta` TO `wpjam_postmeta`; RENAME table `wp_posts` TO `wpjam_posts`; RENAME table `wp_terms` TO `wpjam_terms`; RENAME table `wp_term_relationships` TO `wpjam_term_relationships`; RENAME table `wp_term_taxonomy` TO `wpjam_term_taxonomy`; RENAME table `wp_usermeta` TO `wpjam_usermeta`; RENAME table `wp_users` TO `wpjam_users`;修改Options 表中的數(shù)據(jù) 使用下面語句把 options 表中的 option_name 以 wp_ 開頭的值改成 wpjam_ 開頭。 SELECT REPLACE(option_name,'wp_','wpjam_') FROM wpjam_options;修改UserMeta 表中的數(shù)據(jù) 使用下面語句把 UserMeta 表中的 meta_key 以 wp_ 開頭的值改成 wpjam_ 開頭。
在 wp-config.php 修改數(shù)據(jù)庫前綴
打開你的 wp-config.php 文件,把數(shù)據(jù)庫前綴 wp_ 改成你想要的前綴,比如 wpdx_。
$table_prefix = 'wpdx_';
修改數(shù)據(jù)表名字
打開 PHPMySQL,找到你的數(shù)據(jù)庫,然后執(zhí)行以下 SQL,把所有數(shù)據(jù)庫表前綴從 wp_ 改成 wpdx_ 。
RENAME table 'wp_commentmeta' TO 'wpdx_commentmeta';
RENAME table 'wp_comments' TO 'wpdx_comments';
RENAME table 'wp_links' TO 'wpdx_links';
RENAME table 'wp_options' TO 'wpdx_options';
RENAME table 'wp_postmeta' TO 'wpdx_postmeta';
RENAME table 'wp_posts' TO 'wpdx_posts';
RENAME table 'wp_terms' TO 'wpdx_terms';
RENAME table 'wp_term_relationships' TO 'wpdx_term_relationships';
RENAME table 'wp_term_taxonomy' TO 'wpdx_term_taxonomy';
RENAME table 'wp_usermeta' TO 'wpdx_usermeta';
RENAME table 'wp_users' TO 'wpdx_users';
修改 Options 表中的數(shù)據(jù)
使用下面語句把 options 表中的 option_name 以 wp_ 開頭的值改成 wpdx_ 開頭。
SELECT REPLACE(option_name, 'wp_', 'wpdx_') FROM wpdx_options;
修改 UserMeta 表中的數(shù)據(jù)
使用下面語句把 UserMeta 表中的 meta_key 以 wp_ 開頭的值改成 wpdx_ 開頭。
SELECT REPLACE(meta_key, 'wp_', 'wpdx_') FROM wpdx_usermeta;
ThinkPHP\Common文件夾中的convention.php中是tp的核心配置文件,不能亂動(dòng),如果要想更改里面的配置,在Conf 文件夾里面的config.php可以配置,可以這樣寫
?php
return array(
'DB_TYPE' = 'mysql',// 數(shù)據(jù)庫類型
'DB_HOST' = '127.0.0.1',// 數(shù)據(jù)庫服務(wù)器地址
'DB_NAME' = 'thinkphp',// 數(shù)據(jù)庫名稱
'DB_USER' = 'root',// 數(shù)據(jù)庫用戶名
'DB_PWD' = '123',// 數(shù)據(jù)庫密碼
'DB_PREFIX' = 'tp_',// 數(shù)據(jù)表前綴
'DB_CHARSET' = 'utf8',// 網(wǎng)站編碼
'DB_PORT' = '3306',// 數(shù)據(jù)庫端口
'APP_DEBUG' = false,// 開啟調(diào)試模式
);
?
也可以在最外邊寫,就是與ThinkPHP框架同一目錄中寫一個(gè)config.php文件,格式如同上面的一樣,不過在Conf 文件夾里面的config.php中得包含最外邊的那個(gè)config.php
新聞名稱:php數(shù)據(jù)庫前綴,php的后綴
當(dāng)前網(wǎng)址:http://muchs.cn/article8/hcgcop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、ChatGPT、面包屑導(dǎo)航、App開發(fā)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)