Skip to content

Instantly share code, notes, and snippets.

@wojtha
Created April 11, 2011 14:43
Show Gist options
  • Save wojtha/913623 to your computer and use it in GitHub Desktop.
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
<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} &mdash;&gt; {$table_new} <br />";
}
$db_prefix = $new;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment