通過(guò)下面這個(gè)方法,輕松搞定,代碼如下,有用到的頂起。
<?php
$database = "databaseName"; //數(shù)據(jù)庫(kù)名稱
$user = "root"; //數(shù)據(jù)庫(kù)用戶名
$pwd = "pwd"; //數(shù)據(jù)庫(kù)密碼
$replace ='pre_'; //替換后的前綴
$seach = 'pre1_'; //要替換的前綴
$db=mysql_connect("localhost","$user","$pwd") or die("連接數(shù)據(jù)庫(kù)失?。?quot;.mysql_error()); //連接數(shù)據(jù)庫(kù)
$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)
$table = str_replace($seach,$replace,$name['0']);換成
$table = $replace.$name['0'];
就可以了。