php批量更改数据库表前缀实现方法
通过下面这个方法,轻松搞定,代码如下,有用到的顶起。
<?php
$database = "databaseName"; //数据库名称
$user = "root"; //数据库用户名
$pwd = "pwd"; //数据库密码
$replace ='pre_'; //替换后的前缀
$seach = 'pre1_'; //要替换的前缀
$db=mysql_connect("localhost","$user","$pwd") or die("连接数据库失败:".mysql_error()); //连接数据库
$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");
}
?>
如果是添加前缀只需要变化一点点
$table = str_replace($seach,$replace,$name['0']);换成
$table = $replace.$name['0'];
就可以了。
相关文章
ThinkPHP中Common/common.php文件常用函数功能分析
这篇文章主要介绍了ThinkPHP中Common/common.php文件常用函数功能,通过注释的形式详细分析了C方法、tag方法、B方法及autoload方法的功能与代码原理,需要的朋友可以参考下2016-05-05
配置Apache2.2+PHP5+CakePHP1.2+MySQL5运行环境
因为最近要用PHP做个小东西,新学了PHP。结果学PHP只用了2个小时,配置服务器却用了两天,郁闷得想骂人。为了避免以后忘掉,写个博客留底。2009-04-04
CodeIgniter错误mysql_connect(): No such file or directory解决方法
这篇文章主要介绍了CodeIgniter错误mysql_connect(): No such file or directory解决方法,需要的朋友可以参考下2014-09-09
PHP 面向对象程序设计(oop)学习笔记(三) - 单例模式和工厂模式
设计模式是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。2014-06-06


最新评论