We often encounter the problem of replacing or adding the database table prefix. it is also a method to export data through the database, change it in batch in notepad, and then export the data, but it is not convenient to use the following method to easily solve the problem. The code is as follows, which can be used as a top point.
The code is as follows:
$ Database = "databaseName"; // database name
$ User = "root"; // database username
$ Pwd = "pwd"; // database password
$ Replace = 'pre _ '; // The prefix after replacement
$ Seach = 'pre1 _ '; // The prefix to be replaced
$ Db = mysql_connect ("localhost", "$ user", "$ pwd") or die ("database connection failed:". mysql_error (); // connect to the database
$ 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 ");
}
?>
If you want to add a prefix, you only need to change it a little bit.
The code is as follows:
$ Table = str_replace ($ seach, $ replace, $ name ['0 ']);
$ Table = $ replace. $ name ['0'];
You can.