天天看點

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");

}

?>