批量修改数据库表前缀
<meta charset="utf-8"/> <!-- 遍历所有的数据表改表前缀的程序文件 --> <?php define('DB_NAME', 'animeclub'); define('OLD_PREFIX','emlog_'); define('NEW_PREFIX','anime_'); set_time_limit(0) ; mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_select_db( DB_NAME ) ; $sq = "SHOW TABLES" ; $result = mysql_query($sq); $I = 1 ; while ($row = mysql_fetch_assoc($result)) { $oldT = $row['Tables_in_'.DB_NAME] ; if(strrpos($oldT, OLD_PREFIX ) === 0 ){ $newT = str_replace(OLD_PREFIX, NEW_PREFIX , $oldT) ; } if(isset($newT)){ $resql = "RENAME TABLE {$oldT} TO $newT " ; $rt = mysql_query($resql) ; $c = $rt ? "<font color='green'>成功更改{$I}条记录·····从{$oldT}到{$newT}</font><br/>" : "<font color='red'>更改表名称{$oldT}到{$newT}失败</font><br/>" ; echo $c.'<br/>' ; } $I++ ; continue ; } echo "<hr/><p>处理完成-----------------over....</p>" ; ?>
☜☞梦想总是要有的,万一实现了呢☜☞