通过下面这个方法,轻松搞定,代码如下,有用到的顶起。
<?php<BR> $database = "databaseName"; //数据库名称<BR> $user = "root"; //数据库用户名<BR> $pwd = "pwd"; //数据库密码<BR> $replace ='pre_'; //替换后的前缀<BR> $seach = 'pre1_'; //要替换的前缀<BR> $db=mysql_connect("localhost","$user","$pwd") or die("连接数据库失败:".mysql_error()); //连接数据库</P><P> $tables = mysql_list_tables("$database"); <BR> while($name = mysql_fetch_array($tables)) {</P><P> $table = str_replac<i>·本2文来源gaodai$ma#com搞$代*码网2</i><strong>搞gaodaima代码</strong>e($seach,$replace,$name['0']);<br><br> mysql_query("rename table $name[0] to $table");<BR> }</P><P>?><BR>
如果是添加前缀只需要变化一点点
$table = str_replace($seach,$replace,$name['0']);换成<BR> $table = $replace.$name['0'];<BR>
就可以了。