Most of the time when we write a project, we give a unified prefix to the table names used in different projects, and this also brings some trouble for future migration projects.
Sometimes you migrated the target database already have other projects exist, and their table prefix is exactly the same as yours, so what can be done, only later to indulge, change it!
The following is a batch of my written code to modify the table prefix, for your reference, we hope to help.
PHP code
1<?PHP2 3 $old _pre= @$_get[' Old_pre '];//Original Table Prefix4 $new _pre= @$_get[' New_pre '];//new Table Prefix5 6 $length=strlen($old _pre);//original table prefix length7 8 //Connect to database9 $mysqli= @NewMysqli ("localhost", "root", "" "," WordPress ");Ten One if(Mysqli_connect_errno()) A { - Exit("Connection Database failed:".)Mysqli_connect_error()); - } the - //querying all tables in the current database - $result=$mysqli->query (' SHOW TABLES '); - + Echo"--<pre>\n\r"; - //iterate through all the tables + while($row=$result-Fetch_row ()) A { at $old _tablename=$row[0]; - - //determines whether the table name contains a prefix to modify - if($old _pre&&$old _pre==substr($old _tablename, 0,$length)) - { - $new _tablename=$new _pre.substr($old _tablename,$length); in Echo"ALTER TABLE" {$old _tablename} ' RENAME to ' {$new _tablename}`; \n\r "; - } to + } - Echo"--</pre>"; the * $mysqli->close ();
Change before change
Run (old_pre: Original prefix, leave blank to add a new prefix on the original prefix, New_pre: New prefix, leave the original prefix is deleted)
After modification
PHP Bulk Modify Table name prefixes