Created
April 11, 2011 14:43
-
-
Save wojtha/913623 to your computer and use it in GitHub Desktop.
Change Drupal DB table prefixes in a dirty way using Page with PHP filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="" method="get"> | |
Old prefix: <input type="text" name="old" /> <br /> | |
New prefix: <input type="text" name="new" /> <br /> | |
<input type="submit" value="Rename" /> | |
</form> | |
<?php | |
global $db_prefix; | |
if ($old = $_REQUEST['old'] || $new = $_REQUEST['new']) { | |
$result = db_query("SHOW TABLES"); | |
while ($r = db_fetch_array($result)) { | |
$table_old = current($r); | |
$table_new = $new.str_replace('^'.$old, '', $table_old); | |
db_query("RENAME TABLE {$table_old} TO {$table_new}"); | |
print "{$table_old} —> {$table_new} <br />"; | |
} | |
$db_prefix = $new; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment